|
|
时间服务异常时,Win可能无法同步时间。可从网页中提取时间信息,用命令设置
用到三方工具:Wget.exe 下载:http://bcn.bathome.net/s/tool/index.html
- ::用wget尝试下载页面,返回信息中提取UTC秒数,w32tm转换成北京时间,最后设置时间。
- ::网站:百度搜索“北京时间” //页面:http://www.baidu.com/s?wd=北京时间
- ::百度上获取的为 1970-1-1 0h 到当前时间的 s 秒数
- ::w32tm 使用的是 1601-1-1 0h 到当前时间的 (10^-7)s (即 0.1 微秒 / 100 纳秒)数。
- ::从 1601-1-1 0h 到 1970-1-1 0h 的时间差为 11644473600 s。
- @echo off
- cd/d %~dp0
- echo 校时前:
- echo %date% %time%
- ::提取UTC秒数s(Wget.exe检查https证书时错误并返回),转换为w32tm.exe可用格式
- for /f "tokens=*" %%s in ('"wget "http://www.baidu.com/s?wd=北京时间" 2>&1|findstr "timestamp""') do (
- set "TS=%%s"
- )
- set "T1%TS:*timestamp=%000" ::加三个0变毫秒
- echo\&echo 时间戳:%T1% 毫秒
- title 校时 本机时间校正为北京时间
- set T2=11644473600000
- set/a _T=1%T1:~-9%-1000000000+%T2:~-9%
- set _T_=%_T:~,-9%&set _T=%_T:~-9%
- set/a T_=%T1:~,-9%+%T2:~,-9%+_T_
- ::设置日期时间(增加四个0变每100纳秒)
- for /f "tokens=4,5" %%d in ('w32tm /ntte %T_%%_T%0000') do (date %%d&time %%e)
- echo+
- echo 校时后:
- echo %date% %time%
- pause
复制代码 |
评分
-
查看全部评分
|