Page 1 of 1

How to set the time on a Linux PC

PostPosted: Mon May 28, 2012 1:08 pm
by Leon van Heerden
The Linux Operating System uses the time zone configured to calculate the correct time. So if you have a server in South Africa with the timezone configured as "+2" then it will use the hardware time and add 2 hours.

To set the Operating System time you use the "date" command:

Code: Select all
date 05281304

The format is MMDDHHmm

If you also need to set the year you can add the year after all the other values:
Code: Select all
date 052813042016

The format is MMDDHHmmYYYY


The hardware clock then also needs to be updated to ensure that the system will have the correct time when it is restarted again.

Use this command:

Code: Select all
hwclock --systohc


This uses the system time to set the hardware clock.

Re: How to set the time on a Linux PC

PostPosted: Fri Jun 24, 2016 8:46 am
by Luanda_Junzi
First check both times for System and also Hardware
System time
Code: Select all
Date

Results
Code: Select all
Fri Jun 24 10:06:54 SAST 2016

Hardware Time
Code: Select all
hwclock

Results
Code: Select all
Fri 24 Jun 2016 08:07:19 SAST  -0.528705 seconds

The Hardware clock is correct.
The fore you can just Syc the time, with hwclock -s "-s is the function Set the System Time from the Hardware Clock"
Code: Select all
hwclock -s

Alternative way to setime
Code: Select all
sudo dpkg-reconfigure tzdata

It will give you the prompts you just have to select the right one's
Geographic area: Africa
Time zone: Johannesburg