cmd.exe - Write Internet Time to a file from windows command line

07
2014-07
  • Will

    I want to write the time of an internet time server to a text file from within windows server 2012 command line. Does someone knows how to do that? Thanks!

  • Answers
  • Frank Thomas

    you can hit the NTP server using Telnet, and redirect the standard output to file, or parse it along the line in a script.

    telnet <timeserver> <NTPport>
    

    The server will respond by printing the current time in the response. from there you can grab the standard out, and parse it as you need to.

    Note, some servers may use port 13 (daytime) instead of 123.


  • Related Question

    Where do I find the 'Internet Time' (NTP) settings in Windows 7
  • pelms

    In Windows XP you can get to the 'Internet Time' settings (to select a ntp server or force an update) via the 'Date and Time Properties' in Control Panel.

    Anyone know where this is found in Windows 7?

    Edit:
    As pointed out, I won't be able to do this if attached to a domain.
    My problem was that my PC was trying to sync with 'time.windows.com' which is blocked by out firewall. In the end I changed the registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers) to point to our internal ntp server and the time is now syncing fine.
    (I know that domain computers should sync with their domain controllers but this machine is not actually logged in to the domain most of the time.)


  • Related Answers
  • random
    1. Click on the clock in your system tray
      • This will bring up the calendar and time
    2. Click Change date and time settings...
      • The Date and Time dialog will appear
    3. Click on the Internet Time tab
    4. Click Change settings
      • The Internet Time Settings dialog will appear.

    From here you can select which time server to sync your computer's time to as well as if you want to sync it up right then and there.

  • user1961730

    I don't think windows has ever had native support for ntp. As far as i know, they use Windows Time service (W32Time), which is more unreliable and inaccurate than ntp.