Member-only story
how to change time and timezone in Linux
reference:
Embedded systems sometimes require setting the system time, date, and time zone. On Linux, there are two clocks. The first is a hardware clock that is typically battery-backed and always running. The OS is in charge of the second, known as the system clock. The typical life-cycle is as follows:
- On Linux boot, system clock is synced to hardware clock via script in
/sbin/hwclock
- System clock is used to keep time while OS is running
- On shutdown, hardware clock is synced to system clock
Time/Date
Setting the system time is straightforward. If your application happens to be in C or C++, you can use stime
(preferred) or settimeofday
. Note that it will likely require superuser access. You can also change it directly from the command line using the date
command, date MMDDHHMMYYYY
.
Running date
or date --utc
yields the current system time in local time and Coordinated Universal Time (UTC) respectively.
To manually sync the hardware clock to the new system clock value (rather than waiting until Linux shuts down), use the hwclock
command, hwclock --systohc --utc
. The --utc
option indicates that the hardware clock will be stored in UTC and…