C标准库中的算法:- @echo off
- call :time t
- echo %t%
- pause & exit
-
- :+ Author: Demon
- :+ Date: 2012/8/31
- :+ Website: http://demon.tw
-
- :time
- setlocal
- for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr .') do set %%x
- set /a "year -= 1900, t = (year - 70) * 365 + ((year - 1) >> 2) - 17, leap = year & 3"
- for /f "tokens=%month%" %%i in ("-1 30 58 89 119 150 180 211 242 272 303 333 364") do set /a t += %%i
- if %leap% equ 0 if %month% gtr 1 set /a t += 1
- set /a t += day, t *= 24, t += hour, t *= 60, t += minute, t *= 60, t += second
- endlocal & set %1=%t% & goto :eof
复制代码 反人类的算法:- @echo off
- call :time t
- echo %t%
- pause & exit
-
- :+ Author: Demon
- :+ Date: 2012/8/31
- :+ Website: http://demon.tw
-
- :time
- setlocal
- for /f "skip=1 tokens=1-9" %%a in ('wmic path win32_utctime ^| findstr .') do set /a m=%%e+9,m%%=12,y=%%i-m/10,t=365*y+y/4-y/100+y/400+(m*306+5)/10+%%a-719469,t=t*86400+%%c*3600+%%d*60+%%g
- endlocal & set %1=%t% & goto :eof
复制代码
|