I am running Ubuntu on an ARM based embedded system that lacks a battery backed RTC. Thus, I use the NTP service to update the time to the current time.
I added the following line to $ date ; sudo service ntp stop ; sudo ntpdate -s gov ; sudo service ntp start ; date Thu Jan 1 UTC 1970 * Stopping NTP server ntpd [ OK ] * Starting NTP server [ OK ] Thu Feb 14 UTC 2013 notice the '-b' flag on ntpdate.
Consider that the the '-B' flag it mentions that offsets over 128 ms can take hours to sync using the default 'slew' mechanism The "-q" option tells the NTP daemon to start up, set the time and immediately exit.
The "-g" option allows it to correct for time differences larger then 1000 sec.
For longer term, you should simply configure the NTP daemon to be running always.
This answer should go to the top, because it is correct: ntpdate is deprecated and installing it is a bad idea, because it conflicts with ntp.
From ntpdate's man page: "Force the time to be stepped using the settimeofday() system call, rather than slewed (default) using the adjtime() system call.
This option should be used when called from a startup file at boot time." Many of the answers below do not include it, and that maybe part of the problem in getting things to work.which does not work - syntax error near unexpected token `(', but if it should ping my AP adress I have response from it).Still for official dongle with Broadcom chip there is no time sync (and the same is true for RPi 3 connected using build in Wi Fi), while for dongle with RTL8192CU chip time is updated just after reboot.When I placed the same SD card in Pi Zero time was updated correctly. Edit Problem only occurs when using official Wi Fi dongle (no matter what Pi) or on Pi 3 when using Wi Fi connection.When I switched to other, Chinese dongle (which was plugged to Pi Zero in my first test) time was updated correctly.Yesterday I noticed that the rpi time was wrong (after a short power failure).