Essentially, I want to get an accurate time from a public NTP server, in DOS or powershell.
I know there's the w32tm which can query a remote ntp server, but the result it gives is how much out my computer time is, not the actual time of the remote ntp server.
I've found various windows apps that work exactly as I want, but i can't get the output to a variable to do anything with. I'm dead surprised there's no .exe that just gets the time from a source, or that it wasn't written into w32tm.
Something like ntpquery.exe pool.ntp.org (followed maybe like a timezone or something) with an output of the date / time is all I'm after.
I know there's a command on another question that shows this result:
w32tm /stripchart /computer:foo
Tracking foo [1.2.3.4].
The current time is 19/07/2012 17:39:48 (local time).
17:39:48 d:-00.0000840s o:-25.3004160s [@ | ]
This shows the local system time (which could and in my case is wrong) and how much out it is to the NTP server (example above is 0.00000840s)
If I run this I could get a result of +/- 3000 seconds or even more, which doesn't give me the actual time of the NTP server just tells me how out I am.
What I'm looking for is a way to get the time from the NTP source in DOS / powershell so I can use it as a variable.
$NTPTime = (Get-NtpTime).NtpTime
. This will store the time returned from the default ntp server (pool.ntp.org) in a DateTime data type. You can change which NTP server by using the-server
parameter.