Set the System Time in Mac OS X from the Command Line

Jul 4, 2012 - 13 Comments

Clock

The clock in Mac OS X sets itself automatically by default, but if you want to set the precise time or are looking for a command line solution to set system time, you can do so with a tool called ntpdate, or the standard ‘date’ command.

Set System Date in Mac OS X from Command Line with a Central Time Server

For ntpdate, which sets the date and time based on the time from a central server accessed via the internet, you’d want to point it either at Apple’s time servers or pool.ntp.org as follows to get the exact time:

sudo ntpdate -u time.apple.com

Enter the admin password when asked, and you’ll soon see something like the following:

4 Jul 14:30:11 ntpdate[28267]: adjust time server 17.151.16.14 offset 0.000336 sec

The offset at the end lets you know how divergent the system clock was with the newly set time. In this example, the system clock was off by a laughably small fraction of a second.

You generally don’t need to do this if you use the “Set date and time automatically” feature within the Date & Time system preferences, though by setting clocks through the command line you could be sure that each machine on a network shows the exact same time.

Set the Mac System Date Manually by Terminal Command

Another approach is to set the date manually from the command line by using the “date” command string, where date is in the [mm][dd]HH]MM[yy] format, which is Month Date Hour Minute Year without any separation. This looks something like:

date 0712122318

For that example, it would set the date as “July 12 2018 at 12:23”.

You can learn more about setting the date with date –help, which also specifies that you can even set the seconds if you want to.

The ‘date’ trick is what you’d want to use if the Mac in question does not have internet access for one reason or another.

Topmost image taken from the Flipclock screensaver

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

13 Comments

» Comments RSS Feed

  1. Rae says:

    Here’s the trick without worrying about the date.

    So for the next time, once you install El Capitan, please do a full time machine back to your external drive. I have Apple Time Capsule that I have fresh install fully backed up, no apps installed just OS X. It’s just like your installer on USB.

    So simply restore your fresh copy from time machine backup and you are good to go.

  2. Todd K says:

    This was completely on the money! TYVM

  3. This isn’t any help for those folks who need to update the date with no network connection.
    in that case enter
    date mmddHHMMyy
    so for 1012am March 1st 2020
    date 0103101220
    You probably need to add a sudo before that if you are logged in multiuser mode. (the normal mode)

  4. Gunnar A Reed says:

    Thank you, that 2018 date worked!

  5. jeremy says:

    ntpdate: command not found

    • Paul says:

      sudo sntp -sS time.apple.com

      • Special Monkey says:

        This worked for me on Catalina. However, there was an error about /var/db/ntp-kod. The command still worked to update the time.

        “sudo touch /var/db/ntp-kod” seems to suppress the /var/db/ntp-kod error next time “sudo sntp -sS time.apple.com” is run.

      • Carlos says:

        How Can I do to make this script run at startup without ask for password?

  6. PH_Pride says:

    working perfectly after changing the date using terminal command:

    ntpdate

  7. Simeon says:

    Smashing!

  8. Nigel says:

    Is it possible to automatically set the date/time server through profile manager?

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site