Changing TimeZone in Linux System
-
In a linux system timezones are defined under the directory /usr/share/zoneinfo/.
[root@3a1b47b409f3 /]# ls /usr/share/zoneinfo/ Africa Atlantic Canada EST5EDT GB GMT0 Indian Kwajalein Mexico PST8PDT ROK UTC iso3166.tab tzdata.zi America Australia Chile Egypt GB-Eire Greenwich Iran Libya NZ Pacific Singapore Universal leapseconds zone.tab Antarctica Brazil Cuba Eire GMT HST Israel MET NZ-CHAT Poland Turkey W-SU posix zone1970.tab Arctic CET EET Etc GMT+0 Hongkong Jamaica MST Navajo Portugal UCT WET posixrules Asia CST6CDT EST Europe GMT-0 Iceland Japan MST7MDT PRC ROC US Zulu right [root@3a1b47b409f3 /]#
-
A system identifies timezone from the file /etc/localtime and this file is generally linked with a zone file present in /usr/share/zoneinfo/.
[root@3a1b47b409f3 /]# date Sun Jun 13 17:13:17 UTC 2021 [root@3a1b47b409f3 /]# ls -ld /etc/localtime lrwxrwxrwx 1 root root 25 Jan 13 2020 /etc/localtime -> ../usr/share/zoneinfo/UTC [root@3a1b47b409f3 /]#
-
We can simply change the timezone by linking the file /etc/localtime with the respective zone file from /usr/share/zoneinfo/.
[root@3a1b47b409f3 /]# ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime [root@3a1b47b409f3 /]# date Sun Jun 13 22:44:23 IST 2021 [root@3a1b47b409f3 /]# ls -ld /etc/localtime lrwxrwxrwx 1 root root 32 Jun 13 22:44 /etc/localtime -> /usr/share/zoneinfo/Asia/Kolkata [root@3a1b47b409f3 /]#