There are various ways to change timezones on Linux, but Mytour simplifies it for you with 2 straightforward methods. Follow along with Mytour's guide to effortlessly adjust timezones on your Linux system.
Exploring 2 Ways to Adjust Timezones on Linux
Method 1: Utilizing the /etc/localtime File to Adjust Timezones
Imagine your Linux computer's current timezone is UTC, and you want to switch it to the Pacific Time Zone as illustrated below:
# date
Mon Sep 17 22:59:24 UTC 2010
In certain Linux distributions, such as CentOS, the timezone is managed through the /etc/localtime file.
Remove the existing localtime file in the /etc/ directory using the command:
# cd /etc
# rm localtime
All timezones for the United States are located in the directory /usr/share/zoneinfo/US, as shown below:
# ls /usr/share/zoneinfo/US/
Alaska Arizona Eastern Hawaii Michigan Pacific
Aleutian Central East-Indiana Indiana-Starke Mountain Samoa
Note: For timezones of other countries, navigate to the directory /usr/share/zoneinfo.
Create a symbolic link for the Pacific Time Zone from the US timezones directory above to the /etc/localtime directory:
# cd /etc
# ln -s /usr/share/zoneinfo/US/Pacific localtime
At this point, the timezone on your Linux system will be changed to the Pacific Time Zone as illustrated below:
# date
Mon Sep 17 23:10:14 PDT 2010
Method 2: Changing Timezone on Linux using the /etc/timezone file
In some distributions, such as Ubuntu, the timezone is controlled by the file /etc/timezone.
For instance, if your current timezone is New York, it would be displayed as follows:
# cat /etc/timezone
America/New_York
To switch to the Los Angeles timezone, edit the file /etc/timezone as shown below:
# vim /etc/timezone
America/Los_Angeles
Additionally, you can set the timezone from the command line using the TZ variable:
# export TZ=America/Los_Angeles
With the two methods for changing timezones on Linux introduced by Mytour above, we hope they prove helpful to you. Alongside timezone adjustments, learning how to change IP addresses on Linux using commands will expand your knowledge of using the Linux operating system. Wishing you success!
If you're using Windows and facing time discrepancies, refer to the guide on adjusting time on your computer here
