【发布时间】:2018-03-03 12:08:41
【问题描述】:
我目前有一个批处理脚本,可以将当前日期时间保存到日志文件中。
注意:我从微软论坛获得了这个脚本,因为我不知道如何创建批处理脚本。虽然我知道如何使用 java 进行开发,但在这种情况下我不希望这样做。
@echo off
REM *DATETIME.BAT
REM *Copy date and time to create a new log file
echo.|date>datetime.tmp
echo.|time>>datetime.tmp
IF NOT EXIST datetime.tmp GOTO Error1
type datetime.tmp|FIND "current">datetime.log
rem del datetime.tmp
GOTO End
:Error1
Echo.
Echo There was an error processing the command.
Echo Unable to find temporary sort file DATETIME.TMP.
Echo.
GOTO End
:End
我可以理解这段代码是如何工作的,日志文件中的输出是这样的,例如:
The current date is: 01.01.2018
The current time is: 13:01:17,42
我想知道的是:如何读取 another 脚本中的日期和时间并检查当前时间是否比保存的时间大 1 小时和/或当前日期是否在至少 1 天后。如果条件分别为真或不真,应该有一个特定的返回值。
我希望我能够解释我的问题。谢谢!
【问题讨论】:
-
提供
datetime.tmp的第二行会很有用,因为您给出的示例没有向我们显示哪个是dd,哪个是mm,例如Enter the new date: (mm.dd.yy)
标签: windows date batch-file time comparison