将小时和分钟与批处理文件中的当前时间进行比较 [英] comparing hours and minutes to current time in batch file

查看:92
本文介绍了将小时和分钟与批处理文件中的当前时间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在处理一个批处理文件,它将在启动程序之前将当前时间与指定时间进行比较. 即:批处理文件检查是否已超过上午10点.如果是,请启动程序.如果不是,它将发送一条消息,告知该程序无法在上午10点之前打开.如果已超过下午6点,则该程序将无法启动,并显示一条消息.

I am currently working on a batch file that will compare the current time to a specified time before starting a program. i.e: The batch file checks if it's past 10 am. If it is it start the program. If not, it sends a message telling that the program can't be open before 10 am. If it's past 6 pm, the program won't start and a message appears.

这是我的代码,目前:

@echo off
Set _hourAM=
Set _minAM=
Set _hourPM=
Set _hourPM=
If %_nowh% GEQ %_hourAM% If %_nowm% GEQ %_minAM% (
If %_nowh% LSS %_hourPM% If %_nowm% LSS %_minPM% Goto _approved
) ELSE (

推荐答案

您可以这样做:

@echo off&cls
set "$AM=0950"
set "$PM=1800"
set "$Local_T=%time:~0,2%%time:~3,2%"
set "$Sw_T=True"

if %$Local_T% lss %$AM% set "$Sw_T=False"
if %$Local_T% gtr %$PM% set "$Sw_T=False"

If "%$Sw_T%"=="True" (
  echo Path\to\your\program.exe
  exit /b)
cls&echo "YOU CAN RUN THIS PROGRAM ONLY BETWEEN 09:50 AND 18:00"
pause
exit

要启动程序,您必须替换以下行:

To start your program you have to replace the line :

echo Path\to\your\program.exe

遵循程序的路径.

这篇关于将小时和分钟与批处理文件中的当前时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆