Member-only story

how to change time and timezone in Linux

howtouselinux
3 min readJul 11, 2023

--

Photo by Igor Son on Unsplash

reference:

how to change time in Linux

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:

  1. On Linux boot, system clock is synced to hardware clock via script in /sbin/hwclock
  2. System clock is used to keep time while OS is running
  3. 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…

--

--

howtouselinux
howtouselinux

Written by howtouselinux

subscribe, please. We bring real-world experience, the latest trends, and DevOps tips here. contact me: https://forms.gle/dfhQfmTMFhtLAoaa9

No responses yet