获取时间的批处理命令

2019-07-26 09:56:57 浏览数 (1)

@echo off set panpath=C:pdi-ce-5.4.0.1-130data-integration set kpath=D:3worksZYWSPTkettle

for /f "tokens=2 delims==" %%a in ('wmic path win32_operatingsystem get LocalDateTime /value') do ( set t=%%a ) set Today=%t:~0,4%-%t:~4,2%-%t:~6,2% echo %Today% (获取当前日期)

call :Date2Day %Today% 1 YesterDay (获取当前日期的前一天) echo %YesterDay%

call :Date2Day %Today% -1 AfterDay (获取当前日期的后一天) echo �terDay%

Pause :Date2Day (计算指定天数 前/后 的日期 (封装)) @echo off&setlocal for /f "tokens=1-3 delims=/-:, " %%a in ('echo/%~1') do ( set /a yy=%%a,mm=100%%b%0,dd=100%%c%0) set /a z=14-mm,z/=12,y=yy 4800-z,m=mm 12*z-3,j=153*m 2 set /a j=j/5 dd y*365 y/4-y/100 y/400-2472633 set /a i=j-%~2,a=i 2472632,b=4*a 3,b/=146097,c=-b*146097,c/=4,c =a set /a d=4*c 3,d/=1461,e=-1461*d,e/=4,e =c,m=5*e 2,m/=153,dd=153*m 2,dd/=5 set /a dd=-dd e 1,mm=-m/10,mm*=12,mm =m 3,yy=b*100 d-4800 m/10 (if %mm% LSS 10 set mm=0%mm%)&(if �% LSS 10 set dd=0�%) endlocal&set %~3=%yy%-%f%%mm%%f%-�%&goto :EOF

还有一个方法,没有试过,贴这里,大家有时间可以试一下:

@Echo Off

Echo NewDate = DateAdd^("d", Wscript.arguments^(1^), Wscript.arguments^(0^)^)>Day.vbs

Echo Wscript.Echo NewDate>>Day.vbs

Set ymd=2013-09-30

Set d=10

For /f "tokens=*" %%i in ('cscript /nologo Day.vbs %ymd% %d%') do (Echo 日期加十天 %%i)

Set ymd=2013-09-30

Set d=-10

For /f "tokens=*" %%i in ('cscript /nologo Day.vbs %ymd% %d%') do (Echo 日期减十天 %%i)

Pause

Del /q Day.vbs

0 人点赞