Time zone setup has been done usually while performing the OS installation.If you missed to setup the proper timezone in that point, don’t worry we can setup that later by using simple steps.
Sometimes we may need to change the timezone of systems for various reasons.
Say for example, If you buy a server from third party, they might have set the timezone based on their location.
If so, use the following procedures based on your distributions to change it.
If you are looking for related articles then navigate to the following URLs.
- How To Change The HostName In Linux
- 4 Methods To Change The HostName In Linux
- 10 Methods To Check The HostName In Linux
How to change the TimeZone on systemd system in Linux?
systemd is such a wonderful system manager of Linux system, that comes with many handy tools. It help users to perform many actions easily in Linux system.
It offers a tool called timdedatectl
for updating the timezone in systemd system.
/usr/share/zoneinfo:
This directory contains timezone files./etc/localtime:
This file is symlink with timezone file./etc/timezone:
This file is holding timezone name on debian based systems./etc/sysconfig/clock:
This file is holding timezone name on RHEL based systems.
What is timedatectl?
The timedatectl command is control the system time and date. It may be used to query and change the system clock and its settings.
Use one of the following command to view the current timezone.
Check the current timezone using date command.
$ date
Mon Feb 18 18:40:10 IST 2019
Check the current timezone using /etc/localtime
file.
$ ls -lh /etc/localtime
lrwxrwxrwx. 1 root root 34 Feb 16 03:07 /etc/localtime -> ../usr/share/zoneinfo/Asia/Kolkata
Use the following command to check the current timezone on systemd system.
$ timedatectl
or
$ timedatectl status
Local time: Mon 2019-02-18 18:00:26 IST
Universal time: Mon 2019-02-18 12:30:26 UTC
RTC time: Mon 2019-02-18 12:30:27
Time zone: Asia/Kolkata (IST, +0530)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
If you would like to change the timezone. First we need to get the desired timezone information by running one of the below command.
Use the following command irrespective of the Linux distributions to find the desired timezone.
$ tzselect Please identify a location so that time zone rules can be set correctly. Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. #? 2
Please select a country.
Please select a country. 1) Anguilla 19) Dominican Republic 37) Peru 2) Antigua & Barbuda 20) Ecuador 38) Puerto Rico 3) Argentina 21) El Salvador 39) St Barthelemy 4) Aruba 22) French Guiana 40) St Kitts & Nevis 5) Bahamas 23) Greenland 41) St Lucia 6) Barbados 24) Grenada 42) St Maarten (Dutch) 7) Belize 25) Guadeloupe 43) St Martin (French) 8) Bolivia 26) Guatemala 44) St Pierre & Miquelon 9) Brazil 27) Guyana 45) St Vincent 10) Canada 28) Haiti 46) Suriname 11) Caribbean NL 29) Honduras 47) Trinidad & Tobago 12) Cayman Islands 30) Jamaica 48) Turks & Caicos Is 13) Chile 31) Martinique 49) United States 14) Colombia 32) Mexico 50) Uruguay 15) Costa Rica 33) Montserrat 51) Venezuela 16) Cuba 34) Nicaragua 52) Virgin Islands (UK) 17) Curaçao 35) Panama 53) Virgin Islands (US) 18) Dominica 36) Paraguay #? 49
Please select one of the following time zone regions.
Please select one of the following time zone regions. 1) Eastern (most areas) 16) Central - ND (Morton rural) 2) Eastern - MI (most areas) 17) Central - ND (Mercer) 3) Eastern - KY (Louisville area) 18) Mountain (most areas) 4) Eastern - KY (Wayne) 19) Mountain - ID (south); OR (east) 5) Eastern - IN (most areas) 20) MST - Arizona (except Navajo) 6) Eastern - IN (Da, Du, K, Mn) 21) Pacific 7) Eastern - IN (Pulaski) 22) Alaska (most areas) 8) Eastern - IN (Crawford) 23) Alaska - Juneau area 9) Eastern - IN (Pike) 24) Alaska - Sitka area 10) Eastern - IN (Switzerland) 25) Alaska - Annette Island 11) Central (most areas) 26) Alaska - Yakutat 12) Central - IN (Perry) 27) Alaska (west) 13) Central - IN (Starke) 28) Aleutian Islands 14) Central - MI (Wisconsin border) 29) Hawaii 15) Central - ND (Oliver) #? 20 The following information has been given: United States MST - Arizona (except Navajo) Therefore TZ='America/Phoenix' will be used. Local time is now: Mon Feb 18 06:08:47 MST 2019. Universal Time is now: Mon Feb 18 13:08:47 UTC 2019. Is the above information OK? 1) Yes 2) No #? 1 You can make this change permanent for yourself by appending the line TZ='America/Phoenix'; export TZ to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: America/Phoenix
For systemd systems, use the following command to check the desired timezone information.
$ timedatectl list-timezones | grep America | less America/Adak America/Anchorage America/Anguilla America/Antigua America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba America/Argentina/Jujuy America/Argentina/La_Rioja America/Argentina/Mendoza America/Argentina/Rio_Gallegos America/Argentina/Salta America/Argentina/San_Juan America/Argentina/San_Luis America/Argentina/Tucuman America/Argentina/Ushuaia America/Aruba America/Asuncion America/Atikokan America/Bahia America/Bahia_Banderas America/Barbados America/Belem America/Belize America/Blanc-Sablon America/Boa_Vista America/Bogota America/Boise America/Cambridge_Bay America/Campo_Grande America/Cancun America/Caracas America/Cayenne America/Cayman America/Chicago America/Chihuahua America/Costa_Rica America/Creston America/Cuiaba America/Curacao America/Danmarkshavn America/Dawson America/Dawson_Creek America/Denver America/Detroit America/Dominica America/Edmonton America/Eirunepe America/El_Salvador America/Fort_Nelson America/Fortaleza :
If you got the desired timezone information then go ahead and change it.
How to change the TimeZone in systemd Systems?
For systemd system, use the timedatectl
command to change the timezone.
$ sudo timedatectl set-timezone America/Chicago
If you would like to restart the timedatectl service, use the following command.
# systemctl restart systemd-timedated
Run the following command to verify the new timezone.
# timedatectl
Local time: Tue 2019-02-19 06:08:15 CST
Universal time: Tue 2019-02-19 12:08:15 UTC
RTC time: Tue 2019-02-19 12:08:15
Time zone: America/Chicago (CST, -0600)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2018-11-04 01:59:59 CDT
Sun 2018-11-04 01:00:00 CST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2019-03-10 01:59:59 CST
Sun 2019-03-10 03:00:00 CDT
How to change the TimeZone in RHEL 6/CentOS 6 Systems?
For RHEL/CentOS systems, use the following command to change the timezone.
# unlink /etc/localtime
# ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Run the following command to check the new timezone in RHEL/CentOS systems.
# date Tue Feb 19 04:17:00 PST 2019 # ls -lh /etc/localtime lrwxrwxrwx. 1 root root 39 Feb 17 10:45 /etc/localtime -> /usr/share/zoneinfo/America/Los_Angeles