bea*_*605 12 batch-file unix-timestamp
据我所知,Batch没有给出UNIX时间的命令.我能找到的最接近的是%time%,它只显示时间戳.
批处理中是否有命令或命令集可以获得UNIX时间?
Eit*_*n T 18
有Richie Lawrence的批处理库,它有所有那些漂亮的方便脚本.你需要的是DateToSec(它使用GetDate和GetTime).
这是一个简化的脚本,它使用了一点WMI:
@echo off
setlocal
call :GetUnixTime UNIX_TIME
echo %UNIX_TIME% seconds have elapsed since 1970-01-01 00:00:00
goto :EOF
:GetUnixTime
setlocal enableextensions
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do (
set %%x)
set /a z=(14-100%Month%%%100)/12, y=10000%Year%%%10000-z
set /a ut=y*365+y/4-y/100+y/400+(153*(100%Month%%%100+12*z-3)+2)/5+Day-719469
set /a ut=ut*86400+100%Hour%%%100*3600+100%Minute%%%100*60+100%Second%%%100
endlocal & set "%1=%ut%" & goto :EOF
Run Code Online (Sandbox Code Playgroud)
结果将返回到传递给的第一个参数GetUnixTime,即%UNIX_TIME%.
例如:
1341791426 seconds have elapsed since 1970-01-01 00:00:00
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!
创建一个名为"getUtime.bat"的.bat文件
@echo off
echo WScript.Echo(new Date().getTime()); > %temp%\time.js
cscript //nologo %temp%\time.js
del %temp%\time.js
Run Code Online (Sandbox Code Playgroud)
并像这样打电话
"C:\>getUTime"
1430894237616
Run Code Online (Sandbox Code Playgroud)