CMD日期更改日志

时间:2013-03-19 10:33:56

标签: cmd

我正在制作一个程序,它有一个更改日志。程序更改日志必须说明版本,然后显示它是多少天前。所以应该说:

[2013/03/19, 2 days ago]

我使用了这段代码:

set versionreleasedate1=2013/03/17
set /a verionday=%versionreleasedate1%-%date%

echo Version: 1.0 BETA [2013/03/19, %verionday% days ago]

但是我知道它正在划分的日期,因为cmd认为\符号是代价,我想要一个小日期的sepricator。

所以它会像这样工作

set /a var1=2013/03/17-%date% (todays date)

并回复多少天前。任何帮助都会非常棒。

1 个答案:

答案 0 :(得分:0)

这适用于我的机器,希望对你的机器有效:

@echo off &setlocal
set "versionreleasedate1=2013/03/17"
set "versionreleasetime1=00:00:00,00"

call :GetInternational
call :GetSecs "%versionreleasedate1%" "%versionreleasetime1%" startsec
call :GetSecs "%date%" "%time%" stopsec
set /a versionday=(%stopsec%-%startsec%)/86400
echo Version: 1.0 BETA [%versionreleasedate1%, %versionday% days ago]
goto :eof

:GetInternational
:: Sets a bundle of variables by reading the registry settings
for /f "tokens=1,2*" %%a in (' reg query "HKCU\Control Panel\International"^|find "REG_SZ" ') do set "%%a=%%c"
goto :eof

:GetSecs "dateIn" "timeIn" secondsOut
::  Output:  Seconds elapsed since 1th Jan. 1970 00:00:00
::  http://www.dostips.com/forum/viewtopic.php?p=6450#p6450
setlocal
set "dateIn=%~1"
for /f "tokens=2" %%i in ("%dateIn%") do set "dateIn=%%i"
for /f "tokens=1-3 delims=%sDate%" %%a in ("%dateIn%") do (
  if %iDate%==0 set /a mm=100%%a%%100,dd=100%%b%%100,yy=10000%%c%%10000
  if %iDate%==1 set /a dd=100%%a%%100,mm=100%%b%%100,yy=10000%%c%%10000
  if %iDate%==2 set /a yy=10000%%a%%10000,mm=100%%b%%100,dd=100%%c%%100
)
for /f "tokens=1-3 delims=%sTime%%sDecimal% " %%a in ("%~2") do (
  set "hh=%%a"
  set "nn=%%b"
  set "ss=%%c"
)
if 1%hh% lss 20 set hh=0%hh%
if "%nn:~2,1%" equ "p" if "%hh%" neq "12" (set "hh=1%hh%" &set /a hh-=88)
if "%nn:~2,1%" equ "a" if "%hh%" equ "12" set "hh=00"
if "%nn:~2,1%" geq "a" set "nn=%nn:~0,2%"
set /a hh=100%hh%%%100,nn=100%nn%%%100,ss=100%ss%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2,j=j/5+dd+y*365+y/4-y/100+y/400-2472633,j=j*86400+hh*3600+nn*60+ss
endlocal &set "%~3=%j%"
goto :eof

endlocal

%versionreleasedate1%& %versionreleasetime1%必须采用相同格式,例如%date%&机器上的%time%!