[windows]批處理獲取時間的long型值

大搜車-自娛發表於2014-05-14
@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


The result will be returned into the first parameter passed to GetUnixTime, i.e. %UNIX_TIME%.
For example:

1341791426 seconds have elapsed since 1970-01-01 00:00:00

直接呼叫unix_time函式即可,呼叫方式已經給出了ie例項,還沒有去驗證,同學們可以自己去驗證。

存成一個time2timestamp.bat,然後直接用就可以了

相關文章