how to set date and time


14 posts
by mugliett » Thu Aug 02, 2012 10:21 pm
the date and time are set wrong on my raspberry pi does anyone know how to change it and if so could you explain it to me as i have tried and tried and have got nowhere.
Posts: 2
Joined: Thu Aug 02, 2012 10:15 pm
by Joe Schmoe » Thu Aug 02, 2012 11:05 pm
1) How are you trying to do it?

2) Do you have a working Internet connection on the Pi? Is it present & working during the bootup?
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2769
Joined: Sun Jan 15, 2012 1:11 pm
by mihir_s9 » Thu Aug 09, 2012 8:10 pm
hey even i am stuck at the same, no i dont have a working net connection to the pi...may get that in 2-3 days, but till then is there ant other way to set it??
Posts: 1
Joined: Thu Aug 09, 2012 2:38 pm
by andyroyal » Thu Aug 09, 2012 8:34 pm
From a command time, do something like:

Code: Select all
sudo date -s "Thu Aug  9 21:31:26 UTC 2012"


That should sort you out. For more info on the syntax of the date command:

Code: Select all
man date


should tell you everything you need to know.

Remember that the Raspberry Pi doesn't have a real-time clock (unless you add one yourself) so unless you're connected to the internet you'll have to set the time every time you power on or restart.
Posts: 32
Joined: Fri Jul 20, 2012 7:41 pm
Location: Berkshire, UK
by bredman » Thu Aug 09, 2012 9:05 pm
For more examples of how to set the date/time, see the Command Line Clinic in issue 2 of the free MagPi magazine.
www.themagpi.com
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by Olavxxx » Fri Aug 10, 2012 9:11 am
The Raspberry Pi does not come with a real-time clock,[5] so an OS must use a network time server, or ask the user for time information at boot time to get access to time and date for file time and date stamping. However, a real-time clock (such as the DS1307) with battery backup can be added via the I2C interface.
ref: http://en.wikipedia.org/wiki/Raspberry_Pi

As far as setting it, I did it at the first boot/install screen, while connected to the interwebs.
Posts: 7
Joined: Fri Aug 10, 2012 9:05 am
by sivakumar » Sun Oct 13, 2013 5:57 am
Hello,
If there is internet connection available follow the steps to set the date
1. sudo raspi-config
2. Internationalization options
3. Change Time Zone
4. Select geographical area
5. Select city or region.
6. Reboot your pi.

This way, you will have accurate time. Need not set the date again for every boot.

Warm Regards,
Sivakumar
Posts: 1
Joined: Sun Oct 13, 2013 5:37 am
by bingindo » Thu Jan 30, 2014 3:41 am
sivakumar wrote:Hello,
If there is internet connection available follow the steps to set the date
1. sudo raspi-config
2. Internationalization options
3. Change Time Zone
4. Select geographical area
5. Select city or region.
6. Reboot your pi.

This way, you will have accurate time. Need not set the date again for every boot.

Warm Regards,
Sivakumar



Hi Sivakumar,

That's great, thanks.
btw, do you work with mysql?
thanks.

Cheers,
Bing
User avatar
Posts: 5
Joined: Wed Jan 29, 2014 7:19 am
Location: Indonesia
by Emmadw » Wed Jul 16, 2014 10:08 am
I've had problems with this too ...
I've got the Pi on the network - both using Ethernet & Wifi, and that's fine.
However, it's not updating the time. I've used the suggestion of setting the time zone (or, more to the point, tried changing it to another & back again); and have left it for about an hour, in case it needed time to think about the whole business ...

It used to work out the time - though since the last time I used it, I've updated Raspbian to, I think, the most recent (at least, the most recent that NOOBs has)

Any suggestions?
Posts: 10
Joined: Wed Jul 16, 2014 9:17 am
by DougieLawson » Wed Jul 16, 2014 10:40 am
ntp won't set the date/time if the current clock is off by more than 1000 seconds.

ntpd -q -g
overrides that restriction.

fake-hwclock attempts to store the clock at shutdown so that it's less likely to be that far wrong at restart.
Hacker on ZX80, Microtan65, Raspberry Pis and Arduinos
Unemployed mainframe database troubleshooter
RPi owner since 2012.
Twitter: @DougieLawson

Gaffer tape is "The Force", it has a dark side and a light side and it holds the Universe together.
User avatar
Posts: 7089
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by jojopi » Wed Jul 16, 2014 3:45 pm
DougieLawson wrote:ntp won't set the date/time if the current clock is off by more than 1000 seconds.

ntpd -q -g
overrides that restriction.
Technically true, except that all Linux distributions start ntpd with the -g option by default. Even on systems with an RTC, it would be a bit much to expect the clock to be within 17 minutes of correct at every boot.
User avatar
Posts: 2122
Joined: Tue Oct 11, 2011 8:38 pm
by Emmadw » Thu Jul 17, 2014 2:01 pm
So, from what you're saying, if that is set by default (which it sounds as if it should be), then it shouldn't matter that it's been off for >17 minutes.

However, I have now discovered it must be related to the University network; I tried just now & it didn't update the time/date.
Then, got it to connect to my phone via tethering. Instantly it knew the correct time & date.

Will now try untethering & rebooting (within 17 minutes) to see if it sorts out the time.
Posts: 10
Joined: Wed Jul 16, 2014 9:17 am
by Emmadw » Thu Jul 17, 2014 2:24 pm
I have ... it didn't. :( It didn't reset itself, but it just carried on from the time it had got to before I'd turned it off.

Will contact our Information Services to see if they have any ideas!
Posts: 10
Joined: Wed Jul 16, 2014 9:17 am
by Emmadw » Mon Jul 21, 2014 2:47 pm
I spoke to a colleague, who suggested that it could be the time server. I checked my Mac & discovered its timeserver was one on our local network. So, I used the points in http://raspberrypi.stackexchange.com/qu ... -time-from & edited ntp.conf to reflect the local time server, rather than the ones in the Pi.

It now knows the time :)

Emma

P.S. If you're as clueless as me when it comes to linux, I used the LX Terminal &
Code: Select all
sudo nano ntp.conf
to open the file for editing, then ctrlO to save it.
Posts: 10
Joined: Wed Jul 16, 2014 9:17 am