Timedatectl and Hwclock: Commands to set the date and time in Linux

Timedatectl and Hwclock: Commands to set the date and time in Linux

Timedatectl and Hwclock: Commands to set the date and time in Linux

Timedatectl and Hwclock They are 2 useful commands to adjust the time (date and time), in our GNU / Linux Operating Systems.

Many times when installing and using a GNU / Linux Operating System, some may have appreciated that when starting each time, a user session in the graphical environment or via the terminal, the time (date and time) of the Operating system of the computer change (mismatch). In other cases, it usually changes when you have a configuration of double boot (dual boot) and the use of the Operative Sistems installed.

Timedatectl and Hwclock: Introduction

In the first case described, that is, using only GNU / Linux, many times the problem is dealt with temporarily, that is, not definitively solved, adjusting a clock configuration application graphically or via terminal using command "date".

In the second case, that is, using 2 or more Operating Systems different, usually GNU / Linux and Windows, the problem is usually solved temporarily by manually setting the time from the first to the time (date and time) of the second, and in some cases at the time of BIOS of the computer.

Timedatectl and Hwclock: The problem with UTC

Problem

El time mismatch problem lies, in the way that our GNU / Linux Operating Systems they process the date and time. That is, it is not the same as how it is processed Operating Systems totally different like Windows, although yes like others, such as, MacOS.

En GNU / Linux or MacOS, the pattern is used UTC (Coordinated Universal Time) to set the time of the same, while in Windows not. Windows assumes that the computer stores the correct and updated time in the Motherboard hardware clock, that is, in the BIOS. Since, the Clock and / or BIOS you must keep track of the elapsed time, even when the computer is off.

Therefore, by default, Windows always assumes that the correct time is stored in the Local time (Clock / BIOS) from the computer, while GNU / Linux, as we have already expressed, it assumes that the time is stored in the UTC time, which causes the cyclical time lag marked when using alternately the 2. Therefore, a logical solution is to correctly adjust the Local time (Clock / BIOS) from the computer, and configure each Operating System to communicate with it to synchronize the time to be shown to the user.

Timedatectl and Hwclock Commands

There are commands to solve this problem, that is, to configure that GNU / Linux communicate with hardware (Clock / BIOS) from your computer and syncs with it, to show user the same time, just as you do Windows.

Before being executed, the correct configuration of the time (date and time) in the BIOSAfter executing the command, it is preferable to restart and validate that it remains unchanged, first in the GNU / Linux Operating System and then in the BIOS.

These commands are:

timedatectl

This modern command is special, for those GNU / Linux Distros that they have installed Systemd as Startup process 1 (PID 1)Eg DEBIAN GNU / Linux. Since, it is a functionality provided by this system and services administrator.

To achieve that command, allow GNU / Linux communicate with hardware (Clock / BIOS) from the computer and synchronize with it, the following command must be executed:

sudo timedatectl set-local-rtc 1

For more information about this command, the option «set-local-rtc [BOOL]»And the others, about DEBIAN GNU / Linux, you can access the Online Manual (Manpages) of the packages and commands thereof, on the following link. Or read your local man page by running «man timedatectl«.

hwclock

This legendary and still current command, is special for all types of GNU / Linux Distros, since it does not depend on systemd, nor from any other system and service administrator.

To achieve that command, allow the Operating system GNU / Linux communicate with hardware (Clock / BIOS) of the computer and synchronize with it, that is, configure the time of the same on the BIOS, the following command must be executed:

sudo hwclock -w o sudo hwclock --systohc

Note: For the opposite case, that is, if instead you want to synchronize in reverse (configure the current BIOS time on the Operating System) then you can use the command «hwclock -s»Or the command «hwclock --hctosys«.

For more information about this command, the option «-w»And the others about DEBIAN GNU / Linux, you can access the Online Manual (Manpages) of the packages and commands thereof, on the following link. Or read your local man page by running «man hwclock«.

From now on, when you stop using the UTC pattern for date and time, that is, when using the time (date and time) of the BIOS for GNU / Linux or several Operating Systems, the problem with the hardware time configuration will be avoided and both systems will always have the same time, without lags.

Another alternative procedure for setting the date and time of the GNU / Linux Operating System and sync is with the BIOS from the computer, using the command «date" Y "hwclock»Is the following:

Execute command commands from a root session to set the date 08:00 on March 07, 2020.

  • date --set "2020-03-07 08:00"
  • hwclock --set --date="`date '+%D %H:%M:%S'`"

Generic image for article conclusions

Conclusion

We hope this "useful little post" about «Timedatectl y Hwclock», 2 useful «Comandos de GNU/Linux» used to set the date and time of our «Distros GNU/Linux», especially to solve problems of time mismatches in «ordenadores con doble booteo (inicio)», is of great interest and utility, for the entire «Comunidad de Software Libre y Código Abierto» and of great contribution to the diffusion of the wonderful, gigantic and growing ecosystem of applications of «GNU/Linux».

And for more information, always do not hesitate to visit any Online library as OpenLibra y jedit to read books (PDFs) on this topic or others knowledge areas. For now, if you liked this «publicación», don't stop sharing it with others, in your Favorite websites, channels, groups, or communities of social networks, preferably free and open as Mastodon, or secure and private like Telegram.

Or simply visit our home page at DesdeLinux or join the official Channel Telegram from DesdeLinux to read and vote for this or other interesting publications on «Software Libre», «Código Abierto», «GNU/Linux» and other topics related to «Informática y la Computación», and the «Actualidad tecnológica».


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Octavio dos santos said

    Hello! Thank you very much, the information has helped me, I am using manjaro cinnamon and I had no way to configure graphically, nor the synchronization over the Internet, I simply did not make any changes ... but thanks to you it is already solved 😀

    1.    Linux PostInstall said

      Greetings Octavio! I am glad that the article has served you satisfactorily. Thank you for your comment and contribution.

  2.   Fabian said

    Hello
    in my case I had to change / etc / adjtime as' LOCAL 'instead of UTC' because linux changed the bios time to UTC and windows took it wrong; with
    hwclock –vervose
    I was able to verify that he did not change it again when making that adjustment

    1.    Linux PostInstall said

      Greetings, Fabian. Thank you for your comment and contribution.