Linux list all timezones

How to Check and Set Timezone in Ubuntu 20.04

In this tutorial, you will learn how to check and set the timezone in Ubuntu 20.04 using the timedatectl command.

There are a variety of ways of checking your timezone, from using the date command to the timedatactl command. However, setting your timezone has been greatly simplified and improved with the timedatactl command.

The timedatectl command allows you to output detailed information about your system’s date in time, from NTP info to comparisons between your date with the UTC date.

While we’ve limited the scope of this tutorial to strictly being about setting your timezone, the timedatectl has additional functionality that is very useful for configurations around time and date.

Checking Your Current Timezone

The currently configured timezone is set in the /etc/timezone file. To view your current timezone you can cat the file’s contents.

Another method is to use the date command. By giving it the argument +%Z , you can output your system’s current time zone name.

To get the timezone name and offset, you can use the data command with the +»%Z %z» argument. The uppercase Z prints the timezone name, while the lowercase z outputs the time offset.

The timedatectl command be used to get more details about your system’s current time and date configurations.

 Local time: Sat 2020-09-05 03:09:26 UTC Universal time: Sat 2020-09-05 03:09:26 UTC RTC time: Sat 2020-09-05 03:09:26 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no 

Setting Your Timezone

To set your timezone the timedatectl command will be used. Before you set your new timezone you may want to know what timezones are available. You can list all available timezones using the timedatectl list-timezones command.

timedatectl list-timezones
Africa/Abidjan Africa/Accra Africa/Algiers Africa/Bissau Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/El_Aaiun Africa/Johannesburg Africa/Juba Africa/Khartoum Africa/Lagos Africa/Maputo Africa/Monrovia Africa/Nairobi Africa/Ndjamena Africa/Sao_Tome . 

The timezone list is very extensive. To narrow the list down to only your region you can pipe the results to the grep command. For example, to narrow our results to only the Americas, we would run the following command.

timedatectl list-timezones | grep America
. America/Santiago America/Santo_Domingo America/Sao_Paulo America/Scoresbysund America/Sitka America/St_Johns America/Swift_Current America/Tegucigalpa America/Thule America/Thunder_Bay America/Tijuana America/Toronto America/Vancouver America/Whitehorse America/Winnipeg America/Yakutat America/Yellowknife

Once you know the time zone you want to set your Ubuntu server to, you use the timedatactl set-timezone command to set it.

sudo timedatectl set-timezone America/Toronto

and then confirm your changes were applied by running the timedatactl command.

 Local time: Fri 2020-09-04 23:30:58 EDT Universal time: Sat 2020-09-05 03:30:58 UTC RTC time: Sat 2020-09-05 03:30:59 Time zone: America/Toronto (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no 

Источник

Читайте также:  Installing windows and linux dual boot

Часовые пояса в Linux и timedatectl

Обычно системы на Linux могут получить дату и время при первом соединении с интернетом после установки операционной системы (через «NTP service»). Единственное что не знает система — это текущий часовой пояс, поэтому получается дата по Гринвичу. В итоге, остаётся только изменить часовой пояс, чтобы время и дата стали указываться правильно.

После установки операционной системы первым делом всегда настраивайте дату и часовой пояс. Иначе многие программы будут работать неверно, используя неверное время. Это относится не только к планировщику заданий CRON, но и к СУБД MySQL и Apache серверу. Если не поставите нужную дату сразу, от при изменении её после начала работы проекта могут произойти ошибки в работе программ.

Вт 03 авг 2021 18:44:58 MSK
 Local time: Вт 2021-08-03 18:46:08 MSK Universal time: Вт 2021-08-03 15:46:08 UTC RTC time: Вт 2021-08-03 15:46:08 Time zone: Europe/Moscow (MSK, +0300) System clock synchronized: yes NTP service: active RTC in local TZ: no 

Если часовой пояс указан неверно, то можно его задать без перезагрузки системы. Для этого сначала нужно узнать нужный код (название страны и города) из списка сохранённых с помощью команды:

timedatectl list-timezones
Africa/Abidjan Africa/Accra Africa/Addis_Ababa . Pacific/Tongatapu Pacific/Wake Pacific/Wallis

Список будет очень большим. Чтобы ограничить его можно использовать утилиту «grep», чтобы выделить строки только с нужным регионом. К примеру:

timedatectl list-timezones | grep Europe

После чего необходимо взять название подходящего города/страны (записаны через слеш) и выполнить вместе с ними команду (в примере мы выбрали «Europe/Moscow»):

timedatectl set-timezone Europe/Moscow

При выполнении этой команды часовой пояс сменится на «Europe/Moscow». Чтобы проверить его можно опять выполнить команду «timedatectl» без дополнительных ключей.

Источник

How to Set Time, Timezone and Synchronize System Clock Using timedatectl Command

The timedatectl command is a new utility for RHEL/CentOS 7/8 and Fedora 30+ based distributions, which comes as a part of the systemd system and service manager, a replacement for old traditional date command used in sysvinit daemon based Linux distributions.

Set System Time, Date and Timezone in Linux

The timedatectl command allows you to query and change the configuration of the system clock and its settings, you can use this command to set or change the current date, time, and timezone or enable automatic system clock synchronization with a remote NTP server.

In this tutorial, am going to take you through the ways you can manage time on your Linux system by setting the date, time, timezone, and synchronize time with NTP from the terminal using the new timedatectl command.

It is always a good practice to maintain the correct time on your Linux server or system and it can have the following advantages:

  • maintain a timely operation of system tasks since most tasks in Linux are controlled by time.
  • the correct time for logging events and other information on the system and many more.

How to Find and Set Local Timezone in Linux

1. To display the current time and date on your system, use the timedatectl command from the command line as follows:

Читайте также:  Выключить контроллер usb linux

In the screencast above, RTC time is the hardware clock time.

2. The time on your Linux system is always managed through the timezone set on the system, to view your current timezone, do it as follows:

# timedatectl OR # timedatectl | grep Time

3. To view all available timezones, run the command below:

# timedatectl list-timezones

4. To find the local timezone according to your location, run the following command:

# timedatectl list-timezones | egrep -o "Asia/B.*" # timedatectl list-timezones | egrep -o "Europe/L.*" # timedatectl list-timezones | egrep -o "America/N.*"

5. To set your local timezone in Linux, we will use the set-timezone switch as shown below.

# timedatectl set-timezone "Asia/Kolkata"

It is always recommended to use and set the coordinated universal time, UTC.

# timedatectl set-timezone UTC

You need to type the correct name timezone otherwise you may get errors when changing the timezone, in the following example, the timezone “Asia/Kolkata” is not correct therefore causing the error.

How to Set Time and Date in Linux

6. You can set the date and time on your system, using the timedatectl command as follows:

Set Time in Linux

To set time only, we can use a set-time switch along with the format of time in HH:MM:SS (Hour, Minute, and Seconds).

# timedatectl set-time 15:58:30

You may get the below error when setting the date as shown above:

Failed to set time: NTP unit is active

7. The error says that the NTP service is active. You need to disable it using the below command.

# systemctl disable --now chronyd

Set Date and Time in Linux

8. To set date and time, we can use a set-time switch along with the format of date in YY:MM:DD (Year, Month, Day) and time in HH:MM:SS (Hour, Minute, and Seconds).

# timedatectl set-time '2015-11-20 16:14:50'

How to Find and Set Hardware Clock in Linux

9. To set your hardware clock to coordinated universal time, UTC, use the set-local-rtc boolean-value option as follows:

First Find out if your hardware clock is set to local timezone:

Set your hardware clock to local timezone:

# timedatectl set-local-rtc 1

Set your hardware clock to coordinated universal time (UTC):

# timedatectl set-local-rtc 0

Synchronizing Linux System Clock with a Remote NTP Server

NTP stands for Network Time Protocol is an internet protocol, which is used to synchronize the system clock between computers. The timedatectl utility enables you to automatically sync your Linux system clock with a remote group of servers using NTP.

Please note that you must have NTP installed on the system to enable automatic time synchronization with NTP servers.

To start automatic time synchronization with a remote NTP server, type the following command at the terminal.

To disable NTP time synchronization, type the following command at the terminal.

Summary

These are very easy examples described in this tutorial and I hope you will find them helpful for setting various Linux system clocks and timezones. To learn more about this tool, head over to timedatectl man page.

If you have anything to say about this article, feel free to leave a comment for any more information to add. Stay connected to Tecmint.

Читайте также:  Avahi что это такое linux

Источник

How to Change Timezone in Ubuntu Command Line

Change timezone in Ubuntu

The easiest way to change timezone in Ubuntu is using the timedatectl command.

The syntax is as given below:

sudo timedatectl set-timezone TIMEZONE

Running this command with a provided timezone will change the local time of your computer.

Sounds good? Let’s see it in detail.

Check the current timezone

Before you change your timezone willy-nilly, you should check if you are already in the correct timezone or not.

To do so, simply tun the timedatectl command:

$ timedatectl Local time: Tue 2022-03-01 18:00:00 UTC Universal time: Tue 2022-03-01 18:00:00 UTC RTC time: n/a Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no

The line to focus on is the one that has ‘Local time’ in it. That is the time that your system follows. For example, the local time is shown when you run the date command, it is also used for scheduling your (and every other user’s) cron jobs.

As you can see, my computer’s local time follows the ‘Etc/UTC’ timezone. The UTC timezone is essentially Greenwich Mean Time.

Show all available timezones

If you wish to change the timezone, you must know what are the available options.

To get a list of all available timezones, run the following command:

timedatectl list-timezones

This will present you with a scrollable list.

Once you find the most appropriate timezone, make a note of it.

Since I am living in India, I will use the IST timezone – which is ‘Asia/Kolkata’.

Method 1: Use timedatectl command to change timezone (recommended)

The timezone can be changed using the timedatectl command.

Below is the syntax for changing the timezone:

sudo timedatectl set-timezone TIMEZONE

Replace TIMEZONE with the timezone you made a note of earlier.

For me, it was ‘Asia/Kolkata’. So let us try changing the timezone to it.

$ sudo timedatectl set-timezone Asia/Kolkata $ timedatectl Local time: Tue 2022-03-01 23:30:00 IST Universal time: Tue 2022-03-01 18:00:00 UTC RTC time: n/a Time zone: Asia/Kolkata (IST, +0530) System clock synchronized: yes NTP service: active RTC in local TZ: no

You can see now, my local time changed from UTC to IST.

Take a look at the contents of the directory /usr/share/zoneinfo . If you look closely, you will notice that there are directories which are named after all the continents.

There are ‘Africa’, ‘America’, ‘Asia’, ‘Europe’ and more. If you look into the contents of these directories, you will see the actual timezones.

For example, if I look at the contents of /usr/share/zoneinfo/Asia , I will see the cities of each different timezone. There is Kolkata (IST), Bangkok (ICT), Hong Kong (HKT), Kathmandu (NPT), Taipei (CST) and more.

Select the closest/most appropriate city that follows your timezone and create a symbolic link to /etc/localtime .

Below is an example of setting ‘Asia/Kolkata’ as my timezone using a symbolic link:

$ sudo ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime $ date Tue 01 Mar 23:30:00 IST 2022

Ah, perfect! My computer now has the correct timezone.

You just learned to change timezone on Ubuntu using the terminal. Enjoy 🙂

Источник

Оцените статью
Adblock
detector