Thursday 30 October 2014

Changing Timezone in CentOS

Its common that, we may come across situations to change the timezone of our server. The importance of keeping an accurate time in servers comes,

1) when we are troubleshooting issues with the help of logs. The logging time and the the time when the issue happened is crucial in helping us finding the root cause.

2) In other case we may have automated tasks in which, server has to maintain accurate time to get the tasks running.

In-fact in Centos, it is very easy to change the time zone.

Below is the snippet, which shows the current time of my server.
====
root@manoj [~]# date
Thu Oct 30 19:19:48 PDT 2014
=====

So, it is in PDT.

Now, imagine we have to change it to IST.

Step1: Move back the file "/etc/localtime"  as below:
====
root@manoj [~]# mv /etc/localtime /etc/localtime_back
====

Step2:  Create a link to the available time zones as below:
====
root@manoj[~]# ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
====

Now, check the time of the server.
====
root@manoj [~]# date
Fri Oct 31 07:54:43 IST 2014
====

It's changed to IST. 


NOTE:  In Centos different time zones are available in the location "/usr/share/zoneinfo". You can select any timezone according to your need.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.