同步internet时间

Linux下shell同步时间

方法一:脚本批处理,可以添加到任务计划

W32tm.exe Primary Parameters

Parameter Description

W32tm /?

W32tm command line help

W32tm /register

Registers the time service to run as a service and adds default configuration to the registry.

W32tm /unregister

Unregisters the time service and removes all configuration information from the registry.

w32tm /monitor

[/domain:<domain name>] [/computers:<name>[,<name>[,<name>...]]] [/threads:<num>]

domain – specifies which domain to monitor. If no domain name is given, or neither the domain nor computers option is specified, the default domain is used. This option might be used more than once.

computers – monitors the given list of computers. Computer names are separated by commas, with no spaces. If a name is prefixed with a ‘*’, it is treated as a PDC. This option might be used more than once.

threads – specifies the number of computers to analyze simultaneously. The default value is 3. Allowed range is 1-50.

w32tm /ntte <NT time epoch>

Convert an NT system time, in (10^-7)s intervals from 0h 1-Jan 1601, into a readable format.

w32tm /ntpte <NTP time epoch>

Convert an NTP time, in (2^-32)s intervals from 0h 1-Jan 1900, into a readable format.

w32tm /resync

[/computer:<computer>]

[/nowait]

[/rediscover]

[/soft]

Tells a computer that it should resynchronize its clock as soon as possible, throwing out all accumulated error statistics.

computer:<computer> – Specifies the computer that should resynchronize. If not specified, the local computer will resynchronize.

nowait – do not wait for the resynchronize to occur; return immediately. Otherwise, wait for the resynchronize to complete before returning.

rediscover – Redetect the network configuration and rediscover network sources, then resynchronize.

soft – resynchronize using existing error statistics. Not useful, provided for compatibility.

w32tm /stripchart

/computer:<target>

[/period:<refresh>]

[/dataonly]

[/samples:<count>]

Display a strip chart of the offset between this computer and another computer.

computer:<target> – the computer to measure the offset against.

period:<refresh> – the time between samples, in seconds. The default is 2s.

dataonly – display only the data without graphics.

samples:<count> – collect <count> samples, then stop. If not specified, samples will be collected until Ctrl+C is pressed.

w32tm /config

[/computer:<target>]

[/update]

[/manualpeerlist:<peers>]

[/syncfromflags:<source>]

[/LocalClockDispersion:<seconds>]

[/reliable:(YES|NO)]

[/largephaseoffset:<milliseconds>]

computer:<target> – adjusts the configuration of <target>. If not specified, the default is the local computer.

update – notifies the time service that the configuration has changed, causing the changes to take effect.

manualpeerlist:<peers> – sets the manual peer list to <peers>, which is a space-delimited list of DNS and/or IP addresses. When specifying multiple peers, this option must be enclosed in quotes.

syncfromflags:<source> – sets what sources the NTP client should synchronize from. <source> should be a comma separated list of these keywords (not case sensitive):

MANUAL – include peers from the manual peer list.

DOMHIER – synchronize from a domain controller (DC) in the domain hierarchy.

LocalClockDispersion:<seconds> – configures the accuracy of the internal clock that W32Time will assume when it can’t acquire time from its configured sources.

reliable:(YES|NO) – set whether this computer is a reliable time source.

This setting is only meaningful on domain controllers.

YES – this computer is a reliable time service.

NO – this computer is not a reliable time service.

largephaseoffset:<milliseconds> – sets the time difference between local and network time which W32Time will consider a spike.

w32tm /tz

Display the current time zone settings.

w32tm /dumpreg

[/subkey:<key>]

[/computer:<target>]

Display the values associated with a given registry key.

The default key is HKLM\System\CurrentControlSet\Services\W32Time

(the root key for the time service).

subkey:<key> – displays the values associated with subkey <key> of the default key.

computer:<target> – queries registry settings for computer <target>

w32tm /query [/computer:<target>] {/source | /configuration | /peers | /status} [/verbose]

This parameter was first made available in the Windows Time client versions of Windows Vista, and Windows Server 2008.

Display a computer's Windows Time service information.

computer:<target> – Query the information of <target>. If not specified, the default value is the local computer.

Source – Display the time source.

Configuration – Display the configuration of run time and where the setting comes from. In verbose mode, display the undefined or unused setting too.

peers – Display a list of peers and their status.

status – Display Windows Time service status.

verbose – Set the verbose mode to display more information.

w32tm /debug {/disable | {/enable /file:<name> /size:<bytes> /entries:<value> [/truncate]}}

This parameter was first made available in the Windows Time client versions of Windows Vista, and Windows Server 2008.

Enable or disable the local computer Windows Time service private log.

disable – Disable the private log.

enable – Enable the private log.

  • file:<name> – Specify the absolute file name.
  • size:<bytes> – Specify the maximum size for circular logging.
  • entries:<value> – Contains a list of flags, specified by number and separated by commas, that specify the types of information that should be logged. Valid numbers are 0 to 300. A range of numbers is valid, in addition to single numbers, such as 0-100,103,106. Value 0-300 is for logging all information.

truncate – Truncate the file if it exists.

脚本一

w32tm /config /manualpeerlist:ntp.fudan.edu.cn,0x8 /syncfromflags:MANUAL
net stop w32time//可选
net start w32time//可选

w32tm /resync  保存为bat设置触发器,其实可以随意输入设置重复时间(下拉框时间最小5分钟)

脚本二

@echo off
echo autor OAK
@echo off
echo --------------------------------
@echo off
echo setup time resync every one hour
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient /v SpecialPollInterval /t REG_DWORD /d 3600 /f
@echo off
echo --------------------------------
echo setup w32time auto startup
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time /v Start /t REG_DWORD /d 2 /f
@echo off
echo --------------------------------
@echo off
set /p TimeServer=Please Input The Time Server IP:
net time /setsntp:%TimeServer%
net stop w32time
net start w32time
w32tm /resync

time server:Microsoft time server (time.windows.com) uses NIST,

首先查看与想要同步时间的internet时间服务器的时差:
a.打开cmd输入:
w32tm /stripchart /computer:time.windows.com /samples:5 /dataonly  5个样本
b.如果需要,打开UDP端口123用于外出通信。
c.打开UDP端口123(或您选择的不同端口)来传入NTP traffic。
d.配置PDC emulator 用 :
w32tm /config /manualpeerlist:time.windows.com /syncfromflags:manual /reliable:yes /update

域电脑时间同步

请使用以下步骤配置当前与手动指定计算机同步的客户端计算机,以自动与域结构同步时间。

1.cmd里输入w32tm /config /syncfromflags: domhier /update 点击回车

2.继续输入net stop w32time 回车

可以使用组策略来保持与域中的PDC emulator同步

配置 Global Configuration Settings

Computer Configuration/Policies/Administrative Templates/System/Windows Time Service

配置Windows NTP Client settings here

Computer Configuration/Administrative Templates/System/Windows Time Service/Time Providers

同步时间的软件 ntpdate,这次便是使用系统计划任务调用它进
行同步系统时间。添加计划任务使用 SCHTASKS 命令而不用 AT,设置更丰富更灵活,写
个批处理,运行一次即可,原理是:登录系统用户时同步一次,每个小时同步一次。要注
意的是,如果使用的是 XP 系统,好像时间在 2000 年之前是无法登录系统的,也就不能
省几块前买主板电池了。

注意以下批处理里 SCHTASKS 命令是一行的。

@echo off
sc config Schedule start= auto
net start Schedule

SCHTASKS /Create /RU "SYSTEM" /SC HOURLY /TN timesync /TR "C:\WINDOWS\system32\ntpdate.exe -b time.windows.com" /ST 00:00:00 /SD 2000/01/01

SCHTASKS /Create /RU "SYSTEM" /SC ONLOGON /TN timesync2 /TR "C:\WINDOWS\system32\ntpdate.exe -b time.windows.com"

如果用 AT 命令,需要每小时同步则需要添加多个计划任务,如:

at 10:00 /every:M,T,W,Th,F,S,Su "C:\WINDOWS\system32\ntpdate.exe -b time.windows.com"
at 11:00 /every:M,T,W,Th,F,S,Su "C:\WINDOWS\system32\ntpdate.exe -b time.windows.com"

方法二修改注册表  新建SpecialInterval

注册表项 MaxPosPhaseCorrection
路径 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
注释 该项指定服务可进行的最大正时间校准量(以秒为单位)。如果服务确定某个更改幅度大于所需的幅度,它将记录一个事件。特殊情况:0xFFFFFFFF 表示总是校准时间。域成员的默认值是 0xFFFFFFFF。独立客户端和服务器的默认值是 54,000(15 小时)。
注册表项 MaxNegPhaseCorrection
路径 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
注释 该项指定服务可进行的最大负时间校准量(以秒为单位)。如果服务确定某个更改幅度大于所需的幅度,它将转而记录一个事件。特殊情况:-1 表示总是校准时间。域成员的默认值是 0xFFFFFFFF。独立客户端和服务器的默认值是 54,000(15 小时)。
注册表项 MaxPollInterval
路径 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
注释 该项指定系统轮询间隔所允许的最大间隔(单位是用对数形式表示的秒)。请注意,尽管系统必须根据预定的间隔进行轮询,但是提供程序可以根据请求拒绝生成示例。域成员的默认值是 10。独立客户端和服务器的默认值是 15。
注册表项 SpecialPollInterval
路径 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient
注释 该项指定手动对等端的特殊轮询间隔(以秒为单位)。当启用 SpecialInterval 0x1 标志时,W32Time 将使用此轮询间隔而非操作系统确定的轮询间隔。域成员的默认值是 3,600。独立客户端和服务器的默认值是 604,800。

有关基于 Windows Server 2003 的目录林中的 Windows 时间服务的其他信息,请访问下面的网站:

方法三借助同步时间的软件:AutoCalTime

@echo off
w32tm /config /manualpeerlist:time.windows.com /syncfromflags:manual /reliable:yes /update
w32tm /resync



window时间同步相关推荐

  1. Window系统 时间同步服务器IP地址

    中国国家授时中心的时间服务器IP地址及时间同步方法(附多个时间服务器地址) 大家都知道计算机电脑的时间是由一块电池供电保持的,而且准确度比较差经常出现走时不准的时候.通过互联网络上发布的一些公用网络时 ...

  2. linux sntp 代码,C语言window(linux)平台的SNTP实现

    C语言实现window(linux)平台的SNTP,本程序功能主要是实现电脑(或者设备)时间同步.摘录部分代码: unsigned char liVnMode; /* LeapSecond(2bits ...

  3. 集群机器时间同步设置

    Ntp时间服务器 集群保障时间一致 共有3个方法 手工的改 date –s "2016-01-05" 启动service NTP 基于实体机 7*24 不关机 用脚本在规定时间同步 ...

  4. 解决Windows与Ubuntu双系统时间同步问题

    1 问题发现 本子上装的是Window 10(win7升级)和Ubuntu GNOME 14.04的双系统, 一直以来都发现双系统切换后系统的时间显示有问题 每次都发现进入ubuntu系统的时间显示不 ...

  5. win10时间同步服务器修改

    文章目录 前言 一.通过设置修改 二.通过注册表修改 三.腾讯&阿里NTP服务器 总结 前言 最近在装完双系统后,发现从Linux切换到Window后,Windows的时间不是当前时间,而停留 ...

  6. Windows 时间同步

    一.对于在域中的成员可以通过组策略来进行时间同步 二.对于不在域中的计算机可以通过指定时间服务器的方式进行同步 1. 命令行中输入regedit进入注册表 找到HKEY_LOCAL_MACHINE\S ...

  7. ubuntu双系统时间同步_解决Windows与Ubuntu双系统时间同步问题

    1.问题发现 本子上装的是Window 10(win7升级)和Ubuntu GNOME 14.04的双系统, 一直以来都发现双系统切换后系统的时间显示有问题 每次都发现进入ubuntu系统的时间显示不 ...

  8. 网页显示服务器系统时间,客户端实现正确的服务器时间同步 [转]

    一.问题描述 需要解决的问题很简单,就是如何在页面上比较准确的显示服务器时间.目前比较常用的方法就是根据基准时间使用setTimeout或 setInterval来计算最新的时间,这样的问题在于set ...

  9. 三、FSAS + Novatel接收机和相机时间同步、数据保存、解码等 细节说明

    一.器件说明 1.GNSS 接收机是 Propak6,  如下图所示: 具体得介绍: 1. https://blog.csdn.net/hltt3838/article/details/1106227 ...

最新文章

  1. Java集合详解之Map
  2. Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView
  3. RDKit | 基于scikit-learn将pytorch用于QSAR模型构建
  4. 《C++面向对象高效编程(第2版)》——2.30 has-a关系的重要性
  5. Result Maps collection already contains value for ***的问题
  6. 产品经理必须要了解的经济学原理--“口红效应”
  7. 【二分】【SPFA】架设电话线(jzoj 2132)
  8. Reset Password 重置密码 (CentOS 5,6,7 ; Juniper Networks: SRX100 )
  9. configure: error: cannot guess build type; you must specify one
  10. 两款扒站工具使用说明
  11. 无线传感器网络中低功耗MAC协议—T-MAC
  12. vc语言c1083错误,关于VC编译错误fatal error C1083的解决办法
  13. 利用丁香园数据生成疫情分布地图(R语言)
  14. dede标签详细的dede标签大全,dede标签在线学习
  15. 【复盘】如何写一份教程?
  16. Dynamic OCT 和 Dynamic ODT 详细说明
  17. 如何使用Smartproxy运行无限的运动鞋机器人任务
  18. python鱼眼图像识别_使用OpenCV校准鱼眼镜头的方法
  19. 关于资产和负债的理解
  20. Git之显示分支关系图(十五)

热门文章

  1. 数据结构—栈和队列经典面试题
  2. P2P 之 UDP穿透NAT的原理与实现
  3. 如何让导航条高亮显示
  4. 蓝牙开发那些事(9)——结合代码看a2dp协议
  5. php 合并对象_PHP合并数组对象
  6. 1062: 最大公约数
  7. 基于TextRank算法的单领域多文本摘要(英文摘要)
  8. EclipseSVN更新和提交
  9. js小游戏——五子棋人机大战
  10. FICO_通过参考创建方式批量复制跨科目表的总账科目