Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

Set Diffrent Timezone on AWS Linux AMI Machine


Timezone on AWS Linux AMI


Being a developer or a DevOps engineer usually, we try to get the details as clean and specific as possible.
When it comes to datetime everyone prefers to be on current local or the local that he/she can easily adapt to go out for.
So do we need to go through in this article on AWS(Amazon Web Services) Linux AMI. It is the base Linux system that AWS provides and by default, the timezone is set to UTC.
The time on the Amazon Linux AMI is set, by default to UTC. 

We are taking an example of a developer/DevOps engineer who used to use IST timezone in his daily life and can easily move around it.

Coming to point now let's do the action of changing timezone

UTC to IST on AWS Linux AMI

Get the Local Time File

Usually, on Linux systems, we can get the local time file at  "/etc/localtime". This file will contain the information regarding your system timezone and date time-related information.

Get the Right Timezone File

Now we need to get the exact timezone file which can be found under "/usr/share/zoneinfo/".
This folder will contain all the time zones available under Linux which can be used to change the datetime of our system easily.
Linux Time Zone Info List
Linux Zone Info

Make Changes in Effect Now

We need to create a soft link to our local time file which will be linked to our new timezone file.
For this action, we need to run the following command under terminal/ command prompt.
 ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime
If you are facing any issue regarding permission, please use sudo command to execute the above command like this:
 sudo ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime
Once this is done, you can check immediate effects which will also reflect on the logs and any date time operation on the server/ machine.

You can see the result here in the below image as
Linux Time Zone Change Result
Linux Time Zone Change Result
After this, you must handle it in a permanent way because this is the temporary thing. To make this persist for further sessions of the server/machine you need to make changes in the file located at "/etc/sysconfig/clock"

We need to update the ZONE parameter in this file so that it retains.

This parameter specifies the file under "/usr/share/zoneinfo" that is to be used. 

In our case, it will be  ZONE="Asia/Calcutta"

After this, we are ready to use the system in our own set timezone on the machine for every datetime operation that we perform until unless we explicitly change the datetime or developer express the datetime changes in their code.

Keep Learning and Happy Coding :)

Top #3 Articles