118

What is the command to sync a Windows workstation or server to its configured time source?

Nathan Hartley
  • 1,620
  • 5
  • 26
  • 38
Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
  • 1
    More about W32tm can be found here... https://technet.microsoft.com/en-us/library/bb491016.aspx – Nathan Hartley Dec 01 '16 at 16:17
  • I created a bug ticket for this. Windows fails to sync with time server upon startup, or resume from sleep or hibernation. Windows URI: `feedback-hub:?contextid=58&feedbackid=f15278d4-b20d-4a9a-9693-cdf8fbaaa669&form=1&src=1` <- Place into Windows Run dialogue if you have feedback-hub installed from the windows store – Gabriel Fair Apr 14 '20 at 13:41

13 Answers13

113

As Kyle said w32tm /resync is the modern way to do this. See this Link to Microsoft Knowledgebase (KB 307897) for more information on the w32tm command.

There is also net time which is an older version but perhaps easier.

Seanchán Torpéist
  • 1,808
  • 2
  • 14
  • 10
  • 8
    `w32tm /resync` says "The computer did not resync because the required time change was too big." as my CMOS battery is dead and my computer clock resets on every boot at 1/1/2000 12:00 AM. Any help? – Never Quit Nov 04 '15 at 16:48
  • Found solution as per http://blog.bruteforcetech.com/archives/911 , do not forget to restart W32Time service `net stop W32Time` then retry `w32tm /resync` – Never Quit Nov 04 '15 at 17:14
  • 2
    The link is broken. – Stijn Sanders Oct 11 '17 at 09:26
  • @StijnSanders Thanks, found the original article again and fixed – Seanchán Torpéist Oct 17 '17 at 22:14
  • Thanks, but I was refering to the bruteforcetech.com link. – Stijn Sanders Oct 18 '17 at 08:08
  • @NeverQuit, what is the solution? The solution in your comment is a broken link. – JaredThirsk Jan 21 '18 at 01:21
  • @NeverQuit: For me, the second command fails if W32Time is not running. So your sequence of commands doesn't work. – Lightness Races in Orbit Feb 19 '18 at 16:54
  • 5
    @LightnessRacesinOrbit and the others, if you get the "time change was too big" error, use `w32tm /resync /force`. But if you don't have the service started, run `net start w32time`. Both from an elevated prompt. – cdlvcdlv May 25 '18 at 15:13
  • 5
    To solve 'time change was too big' change registry entries MaxNegPhaseCorrection and MaxPosPhaseCorrection in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config to maximum (ffffffff) – Tomas F. Sep 03 '18 at 10:02
  • In Windows server 2016, there is no `/force` for `w32tm` – Ding-Yi Chen Jul 19 '19 at 06:50
  • @Never Quit : after w32tm service i stopped, then w32time /resync prints error because service is not working. – Znik Aug 28 '19 at 11:35
  • 1
    @NeverQuit / @-StijnSanders / @-JaredThirsk - Here is an archive of the bruteforcetech article: [Windows Time Service does not sync, even after all settings verified | BFTech Impressions](http://web.archive.org/web/20151029015046/http://blog.bruteforcetech.com/archives/911). And, there is this article which is referred to in the bruteforcetech article: [Make Windows synchronize time more often](https://www.pretentiousname.com/timesync/). – Kevin Fegan Jul 12 '20 at 00:10
  • @StijnSanders - See my comment above. – Kevin Fegan Jul 12 '20 at 00:11
  • @JaredThirsk - See my comment above. – Kevin Fegan Jul 12 '20 at 00:12
55

For those that still asking this question.

  1. To update, use the command below (2008 and 2012 server compatible)

    w32tm /config /manualpeerlist:"ntp_server" /syncfromflags:manual /reliable:yes /update
    

change the ntp_server with your source

  1. Restart the time service

    net stop w32time
    net start w32time
    
  2. Resync the time

    w32tm /resync
    
  3. Verify your sync status

    w32tm /query /status
    

Commands above should be fine if your sources are working correctly and/or your connection is OK (firewall or Microsoft Forefront can be an issue also). The commands below can help with troubleshooting

To list out peers

w32tm /query /peers

To list out NTP Sources:

w32tm /query /source
sebix
  • 4,175
  • 2
  • 25
  • 45
user3011708
  • 651
  • 5
  • 2
  • As a note, this works for Windows 10 Professional without the "/update" flag as that is invalid. – Fmstrat Dec 04 '17 at 15:56
  • 2
    For troubleshooting, it's often useful to test the connection to a specific server: `w32tm /monitor /computers:time.windows.com` – Randy Orrison Mar 12 '19 at 14:44
25

You can use the following command:

w32tm /resync

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
21

You can use:

w32tm /resync

Additionally, using w32tm /resync /rediscover will also "force redetection of network resourced before resynchronization."

Or using:

net time /set

Will prompt you to set the time to the DC. (Works for older versions of Windows)

Ploni
  • 103
  • 6
Brett Larson
  • 854
  • 1
  • 12
  • 20
  • 4
    For some reason `w32tm /resync` didn't work for me but `net time /SET /Y` did. I used `/Y` for `net time` because it apparently doesn't read stdin properly when going through sshd from cygwin. – qwertzguy Jan 14 '15 at 03:40
  • 2
    When running `w32tm /resync` I got the message `The computer did not resync because no time data was available.` even after a service restart but `net time /SET` worked properly for me. – Chris Magnuson Apr 03 '17 at 12:32
5

OS: MS Windows 7

All above ideas have been tried but did not help. The original problem still exists: "The computer did not resync because the required time change was too big."

Solution is found in the registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\w32time\Config

  • change this if the local time is in a hurry (e.g. 31-Dec-2050): MaxNegPhaseCorrection
  • change this if the local time is delayed (e.g. 1-Jan-1980): MaxPosPhaseCorrection
  • The default values are 0xD2F0 (i.e. 54000 sec. = 15 hours)

(use Google for more details)

I use this simple win_clock_sync.bat file from Start Menu StartUp:

echo off
echo Sync computer time from internet
echo.
echo Back-up registry w32time\Config
reg export HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\w32time\Config exported_w32time.reg /y
rem changing the registry keys temporarly:
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxNegPhaseCorrection /d 0xFFFFFFFF /t REG_DWORD /f
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxPosPhaseCorrection /d 0xFFFFFFFF /t REG_DWORD /f
echo.
echo w32tm /config /update
w32tm /config /update
echo.
echo w32tm /resync /rediscover 
w32tm /resync /rediscover 
echo.
echo Restore registry w32time\Config
reg import exported_w32time.reg

Enjoy! :-)

Akos
  • 61
  • 1
  • 2
  • 1
    Your answer could use an explanation of the function of the `MaxNegPhaseCorrection` and `MaxPosPhaseCorrection` values instead of suggesting that they should be blindly disabled. That's what this script does by setting their data to **0xFFFFFFFF**. – I say Reinstate Monica May 13 '17 at 18:45
  • You cannot ignore the mentioned error message "The computer did not resync because the required time change was too big." without changing the data in the MaxNegPhaseCorrection and MaxPosPhaseCorrection values. Or, did YOU find any working solution to the original problem?? And why are you writing "blindly"? If you would take a short time to read through then you could see the exporting and importing the original data of these values, what is a bit far from doing something "blindly". – Akos May 14 '17 at 07:50
  • You should have this script change the values to disabled, force an update, and then change them back to recommended values. – Cory Knutson Jun 02 '17 at 18:57
  • @Akos Downvote retracted based on your pointing out that your script indeed does revert the changes to the `MaxNegPhaseCorrection` and `MaxPosPhaseCorrection` values. I still encourage including an explanation of what these two settings do as they're a key feature of your answer and it's important that an admin be aware that should they put these settings in place permanently they would configure their system to accept any time change, no matter how large, which could break Kerberos and other important network services. – I say Reinstate Monica Jul 07 '17 at 02:39
  • Twisty has valid points that do not really focus on the issue raised by NeverQuit... but then Akos has not clearly explained why the script is an appropriate solution for NeverQuit. In essence, the Registry values MaxNegPhaseCorrection and MaxPosPhaseCorrection exist to stop the W32Time service from applying dramatic changes to current time [in circumstances such as an external time source going badly awry] However, if some issue occurs that leads to a PDCe drifting rapidly from a reliable time source, then the correction controls will prevent w32tm fixing the big drift. In this situation::: b – Creaky_Uncle_Nick Jul 06 '17 at 10:32
  • @TwistyImpersonator I think within the context of this question (dead CMOS battery), it's a fairly safe "hack". You are right, the max positive and negative delta (which is kinda obvious from the names of the variables) are there for a good reason, and are part of the NTP protocol, however, when you have a dead CMOS battery and a system clock that boots up to ctime 0 (or something equally useless) on every boot, I think this is an appropriate temporary measure until the machine is retired or its CMOS battery is replaced. – Rouben Jul 25 '18 at 15:34
  • It works on XP too if you remove confimation switch `/y`. Tested. Thanks. – Hrvoje T Dec 03 '18 at 07:18
4
  • change your time server
w32tm /config /manualpeerlist:"0.pool.ntp.org 1.pool.ntp.org" /syncfromflags:manual /update
  • fore update time
w32tm /resync /force
user5723841
  • 141
  • 2
4

Powershell one liner if ntp server is configured:

gsv w32time | sasv; w32tm /resync /force

You can put this .bat file in the startup if you CMOS batery failed so it can resync upon OS start:

@powershell -NoProfile -Command 'gsv w32time | sasv; w32tm /resync /force'
GAThrawn
  • 2,424
  • 3
  • 20
  • 38
majkinetor
  • 361
  • 3
  • 9
1

Based on my research, I bookmarked this:

  1. If Hyper-v host server is a part of the same domain, disable time sync for PDC guest vm

  2. On PDC(or any single workstation), update from quoted internal DNS or ip untrusted address(0x8):

    W32tm /config /manualpeerlist:"192.168.0.254,0x8" /syncfromflags:manual /reliable:yes /update

    Powershell Restart-Service w32time

    W32tm /resync /nowait

  3. on dc that is not PDC:

    w32tm /config /syncfromflags:domhier /update

    W32tm /resync /rediscover

  4. On servers and other stations for update time only, not config:

    W32tm /resync /nowait

  5. Check that time is really updating(difference ):

    w32tm /stripchart /computer:192.168.0.254 /samples:15 /dataonly

  6. if time service broken or failed and need reset:

    Powershell Stop-service w32time W32tm /unregister Timeout 30 W32tm /register Powershell Start-service w32time

Note: NTP port is 123 UDP and should give the same output on any healthy computer

Powershell Get-NetUDPEndpoint -LocalPort 123


LocalAddress                             LocalPort
------------                             ---------
::                                       123
0.0.0.0                                  123

Other commands w32tm /query /status w32tm /query /peers w32tm /query /configuration

Best practice from ms: Time Sync best practices

1
net start w32time
w32tm /resync

According to Riot Games

Nato Boram
  • 111
  • 5
0

Nothing worked for me because "The computer did not resync because the required time change was too big.", I ended up using node with ntp-client to set the approximated current time and then be able to resync

.bat file

::time service needs to be started before changing time
net start W32Time
node.exe time_set.js
w32tm /resync
pause

time_set.js

const ntp_server = 'localhost'; //replace with your ntp server address
const ntp_port = 123; //replace with your ntp server port

const ntp_client = require('ntp-client');
const {exec} = require('child_process');

//get ntp time
ntp_client.getNetworkTime(ntp_server, ntp_port, (err, ntp_date) => {
  //exit with error code
  if (err) { process.exit(1); }
  //go back to 23:59:30 if close to midnight
  if (ntp_date.getHours() === 23 && ntp_date.getMinutes() === 59 && ntp_date.getSeconds() > 30) {
    ntp_date.setSeconds(30);
  }
  //set date
  exec(`date ${ntp_date.toLocaleDateString()}`, {shell: true});
  //set time
  exec(`time ${ntp_date.toLocaleTimeString()}`, {shell: true});
});

Notes:

  • This has to be run as administrator
  • This seems to work with different default regional formats. If you are setting custom date and time formats, set them after synchronizing time.
  • If you need custom date and time formats support you might need to read the formats from the registry HKEY_CURRENT_USER\Control Panel\International (most likely values sShortDate and sTimeFormat) and then manually format the date or use a tool like date-and-time
Dan
  • 101
  • 1
0

Almost none of the solutions (except @Akos) work if the host is an Windows Server 2016 Active Directory Domain Controller (ADDC), as it treats itself as a "reliable" source that cannot make big time change.

w32tm /resync /force does not work, because the /force does not appear in server 2016.

net time /SET /Y does not work either, because it would have asked:

Do you want to set the local computer's time to match the time at \AD.example.net? (Y/N) [Y]

Of course, it won't work if you are on AD.example.net, /Y just hides the question.

The steps work for me using PowerShell:

  1. Set w32time service as unreliable:
w32tm /config /reliable:no /syncfromflags:manual /update

Option /syncfromflags:manual means sync with NTP listed in peer list (i.e. external NTP), /update for notifying the time service the configuration have changed.

  1. Restart the w32time
Stop-Service w32time
Start-Service w32time
  1. Sync
w32tm /resync

This should work.

  1. If you DO need ADDC as a reliable time source, make it reliable again:
w32tm /config /reliable:yes /update
Stop-Service w32time
Start-Service w32time
Ding-Yi Chen
  • 111
  • 4
0

I have a Win10 image that I can restore to a snapshot where this error message is always reproducible: "The computer did not resync because the required time change was too big."

I have tried to script a solution to this problem with no avail:

reg import nettime.reg # updates MaxPosPhaseOffset and MaxNegPhaseOffset

net start w32time
w32tm.exe /config /manualpeerlist:"pool.ntp.org",0x8 /syncfromflags:manual /reliable:no /update  
w32tm.exe /query /configuration
w32tm.exe /resync /rediscover
w32tm.exe /resync /force

Neither the /reliable:no nor the MaxPosPhaseCorrection settings, nor any other commands indicated here worked immediately in a reproducible way.

After updating the registry, starting the service, updating the configuration and again restarting the service I still had to wait many minutes before I w32tm /resync /rediscover would succeed.

The time syncronization does succeed eventually, just not in a timely and reliable manner.

-2

Try in this order. Works all the time.

w32tm /unregister

w32tm /register

net stop w32time

net start w32time

w32tm /resync
slayernoah
  • 1,570
  • 2
  • 12
  • 19
  • I had to wait about 10 minutes between the first and second commands because of a `The following error occurred: The specified service has been marked for deletion. (0x80070430)` error. Then the next 3 commands worked, but the `w32tm /resync` command results in `The computer did not resync because no time data was available.` – pacoverflow May 04 '20 at 06:15