Bat 脚本将时间转换为 NT 时间戳 - 使用指南
以下是一个将输入时间转换为 NT 时间戳的 Bat 脚本,使用方法如下:
-
将以下代码复制到一个文本编辑器中,保存为 .bat 文件,如 'timestamp.bat'。
-
在命令行中输入 'timestamp.bat [时间字符串]',其中 '[时间字符串]' 为要转换的时间,如 '2021-05-01 12:00:00'。
-
执行后,会输出该时间的 NT 时间戳。
@echo off
setlocal
rem 获取输入的时间字符串
set time_str=%1
rem 将时间字符串转换为 NT 时间戳
for /f "tokens=1-6 delims=- : " %%a in ('%time_str%') do (
set /a year=%%a, month=1%%b-100, day=1%%c-100, hour=1%%d-100, minute=1%%e-100, second=1%%f-100
)
set /a year-=1601
set /a month=(month+9) %% 12 + 1
set /a a=(14-month)/12
set /a y=year+a
set /a m=month+12*a-2
set /a d=(day+306+(153*m+2)/5+y*365+y/4-y/100+y/400-719469)*864000000000
set /a h=hour*36000000000
set /a min=minute*600000000
set /a sec=second*10000000
set /a timestamp=%d%+%h%+%min%+%sec%
echo %timestamp%
endlocal
原文地址: https://www.cveoy.top/t/topic/oc0x 著作权归作者所有。请勿转载和采集!