Change Time and Date on almost all linux distros

How to Set Time and Date on Different Linux Distributions

Linux is a versatile and powerful operating system that can run on various devices, from desktops and laptops to servers and embedded systems. However, Linux systems may have different ways of setting the time and date, depending on the distribution, the hardware, and the configuration. In this article, we will explore some of the common methods to set the time and date on Linux systems, and how to synchronize them with an external source.

Method 1: Using the “date” Command

The “date” command is a simple and quick way to set the time and date on Linux systems. It can be used in various contexts, such as in scripts, cron jobs, or terminal sessions. The syntax of the “date” command is:

date [options] [format]

The options are optional flags that modify the behavior of the command. The format is a string that specifies how to display or set the date and time. For example:

date -s "2023-12-01 12:00:00" sets the system time to December 1st, 2023 at 12:00 PM.

date -R "2023-12-01 12:00:00" sets the system time to December 1st, 2023 at 12:00 PM in UTC.

date -u "2023-12-01 12:00:00" sets the system time to December 1st, 2023 at 12:00 PM in UTC.

The format string can contain various directives that control how to display or set different parts of the date and time. For example:

%Y displays or sets the year with four digits.

%m displays or sets the month with two digits (01-12).

%d displays or sets the day of month with two digits (01-31).

%H displays or sets the hour with two digits (00-23).

%M displays or sets the minute with two digits (00-59).

%S displays or sets the second with two digits (00-59).

You can find more information about these directives in [this article].

Method 2: Using the “timedatectl” Command

The “timedatectl” command is a modern tool that provides information about and control over various aspects of time synchronization on Linux systems. It is part of systemd-timesyncd.service by default on most Debian-based distributions (such as Ubuntu), but it can also be installed manually on other distributions. The syntax of the “timedatectl” command is:

timedatectl [options]

The options are optional flags that modify the behavior of the command. For example:

-a: shows all available options.

-b: shows all available units.

-c: shows all available commands.

-d: shows all available dates.

-e: shows all available times.

-f: shows all available formats.

-h: shows help information.

-i: shows current settings.

-l: lists available units.

-m: lists available commands.

-n: lists available dates.

-p: lists available times.

-r: resets settings to default values.

-s`: shows current settings in a human-readable format.

-t`: tests if systemd-timesyncd.service is active or not.

-u`: updates system clock from NTP server(s).

-v`: verbose mode (shows more details).

You can find more information about these options in this article.

To use this command, you need to know your current timezone information. You can check it by running:

timedatectl status

This will show you your local timezone name (such as Etc/UTC), your RTC time (the hardware clock time), your system clock synchronized status (yes or no), your systemd-timesyncd.service status (active or inactive), your RTC in local TZ flag (yes or no), and your NTP service status (active or inactive). If you want to change your timezone name, you can use one of these commands:

timedatectl list-timezones

This will show you a list of all supported timezones on your system. You can search for one using grep:

timedatectl list-timezones | grep York

This will show you only those timezones that contain York in their name. To change your timezone name, use one of these commands:

timedatectl set-timezone <timezone>

This will set your timezone name to <timezone>. For example:

timedatectl set-timezone America/New_York

This will set your timezone name to America/New_York. To confirm that you have changed it successfully, run:

timedatectl status

You should see something like this:

Local time: Wed Dec 01 12:00: