Wednesday, January 17, 2018

linux: Reset the time zone

If your time is off by exactly one hour or hours, it is possible that the time zone or DST(Daylight Saving Time) is not set correctly.

Time zone and DST information is stored in the /usr/share/zoninfo directory. To reset the time zone, firstly pick the right time zone you want to use from the list here or from the /usr/share/zoninfo directory on your machine.

To view the current time of the time zone:
      [root@MyServer ~]# zdump  EST5EDT
      EST5EDT  Wed Jan 17 13:35:19 2018 EST

To view the DST of the time zone:
      [root@CSdevtst ~]# zdump  -v EST5EDT | grep 2018
      EST5EDT  Sun Mar 11 06:59:59 2018 UTC = Sun Mar 11 01:59:59 2018 EST isdst=0 gmtoff=-18000
      EST5EDT  Sun Mar 11 07:00:00 2018 UTC = Sun Mar 11 03:00:00 2018 EDT isdst=1 gmtoff=-14400
      EST5EDT  Sun Nov  4 05:59:59 2018 UTC = Sun Nov  4 01:59:59 2018 EDT isdst=1 gmtoff=-14400
      EST5EDT  Sun Nov  4 06:00:00 2018 UTC = Sun Nov  4 01:00:00 2018 EST isdst=0 gmtoff=-18000

The local time zone is determined by a symbolic link from /etc/localtime to one of the files in the /usr/share/zoninfo directory or its subdirectory. The way to change the time zone is to reset this symbolic link.

      For example, the time zone is currently set to Central Time
      [root@MyServer ~]# ls -l /etc/localtime
      lrwxrwxrwx 1 root root 27 Jan 16 18:03 /etc/localtime -> /usr/share/zoneinfo/CST6CDT

      [root@MyServer ~]# date
      Tue Jan 16 18:29:45 CST 2018

      To change the time zone to Eastern Time
       [root@MyServer ~]# mv /etc/localtime /etc/localtime.old

       [root@MyServer ~]# ln -s /usr/share/zoneinfo/EST5EDT /etc/localtime

      [root@MyServer ~]# date
      Tue Jan 16 18:29:55 EST 2018

After you reset the time zone, synchronize your hardware clock.

      [root@MyServer ~]# hwclock --systohc

If the above method of resetting time zone does not work, you can add export TZ=<time zone> to your .bash_profile. For example

       export TZ=US/EASTERN
       or
       export TZ=EST5EDT

--------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.




No comments:

Post a Comment