batch-file - 批处理日期时间戳比较

标签 batch-file timestamp compare

嘿,我有这个小批处理文件,它应该比较两个文件的时间戳并返回 errorvlvl 0 或 2,具体取决于源文件是否较新(它传递 2 个文件名作为参数),但我不认为gtr 对于时间戳来说是正确的。我有时工作,而不是其他时间...我如何将时间戳解析为整数来比较它们。 顺便说一句,变量 source 和 dest 看起来像这样(我回显它们以查看)
2012年5月6日 18:46

 REM I use the t prefix here to expand the file location parameters passed in, i       into  date/time values
set source=%~t1
echo %dest%
set dest=%~t2
echo %source%

if "%source%" gtr "%dest%" goto overwrite
exit /b 0 
:overwrite
REM if the source file is newer compare.bat will return an errorlevel of 2, this will    then be used in an if statement in the file that called compare.bat to go ahead and overwrite the older file
exit /b 2 

预先感谢您的任何建议! :)

最佳答案

好的。我明白了..我想!

set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~6,4%%dest:~11,2%%dest:~14,2%

关于batch-file - 批处理日期时间戳比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10902272/

相关文章:

batch-file - 批;使用 for 在变量内运行命令

java - 如何在一小时后杀死特定的 java 文件,而不知道它的特定 PID?

javascript - 时间戳转换 : Get day, 日期、小时、分钟等,无需创建 "new Date()"

mysql - 从未知时间戳转换为可读时间戳

tomcat - 当用户在 services.msc 中手动启动服务时,在启动 tomcat 服务之前运行批处理文件

string - 批处理 : Handle numbers above 2^32

windows - 正确地为批处理脚本创建的日志文件加上时间戳

c++ - 比较具有相同逻辑的2个源代码

Java JTextField 在内部类的方法调用中不起作用

比较字符串中的单词