Answered by the Webhosting Experts

How to Change/Set Date, Time, & Timezone on a Linux Server

The date, time, and timezone are important aspects of a Linux system that affect how it operates and interacts with other systems. There are different ways to describe and change these settings in Linux, depending on the distribution and the tools available. Below you will find information on how to display the current date, manually change the system date and time, and set timezones in Linux using the command line and these simple commands.

Display Date in Linux

You can use the date command to display the current date and time:

Screenshot showing the result of the date command.

Using Menu-Based Time Zone Selection

tzselect is a Linux utility that allows users to select a timezone from a list of regions and cities. The utility outputs the timezone description to standard output, which can be used as a value for the TZ environment variable. tzselect does not change the system timezone permanently, it only affects the current shell session. To change the system timezone permanently, other methods such as timedatectl or symlinking can be used, although at the end of this prompt you will see the method used with tzselect to make the change persistent.

Begin by running the following command:

tzselect

Screenshot showing the results of the tzselect command.

For this example, we select 2 for Americas. Next, select the country.

Screenshot showing a list of available countries.

For this example we will select 10 for Canada.

Screenshot showing a list of available timezones.

Then the next screen will display the selection made along with checking whether the information is correct.

Screenshot showing the selection of Canada with a Pacific timezone and asking for confirmation.

Once we confirm the selection you can view the details changed below. This screen also provides information on how to keep the change persistent by appending a line to the .profile file in your home directory.

Screenshot showing confirmation of the information entered above.

Changing Time Zone Using timedatectl

timedatectl is a command-line utility that allows you to view and change the system time, date, and timezone. It can also synchronize the system clock with a remote server using the Network Time Protocol (NTP). timedatectl is part of the Systemd system and service manager.

To view all available time zones, use the following command:

timedatectl list-timezones

Screenshot showing the results of the timedatectl list-timezones command.

Since the list is long, you can also use timedatectl list-timezones | grep EST to search for the value EST. Of course, you can change EST to any other zone you’d like to find, for example Paris, as shown below.

Screenshot showing the results of the timedatectl list-timezones | grep Paris command.

Next, use the following command format: sudo timedatectl set-timezone Region/Location, while changing the Region/Location to your desired result.

For example: Africa/Freetown

Screenshot showing the results of the sudo timedatectl set-timezone Region/Location command.

Manually Setting a Date and Time in Linux

To manually set a new date and time in Linux, use the following syntax:

date -s=”Date and time information” as shown below.

date -s “2 June 2023 14:05:00”

Screenshot showing the results of the date -s "2 June 2023 14:05:00" command.

Changing a Timezone in Linux

The /etc/localtime is a file that configures the system-wide timezone of the local system that is used by applications. It should be an absolute or relative symbolic link pointing to /usr/share/zoneinfo/, followed by a timezone identifier such as “Europe/Berlin” or “Etc/UTC“.

/usr/share/zoneinfo is a directory that contains files with information about timezones. The files are named after each time zone, such as “America/New_York” or “Europe/London“. These files contain information about the timezone rules and daylight saving time (DST) settings for that timezone.

The contents of /etc/localtime can be found below.

Screenshot showing the contents of the /etc/localtime file.

The contents of /usr/share/zoneinfo can be found below.

Screenshot showing the contents of the /usr/share/zoneinfo file.

To set the timezone of your choice, use the example below which uses Calcutta (IST) for the local time on the system, and replace it with the timezone of your choice.

*NOTE: Creating this link will create a link named “localtime” in whichever directory you are running this command. Any other utility to change the timezone used after will not work as this link will take precedence over anything else. To resolve this, you can remove the link/file “localtime” when it is required.

ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime

Screenshot showing the results of the ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime command.

 

Popular Links

Looking for more information on Linux? Search our Knowledge Base!

Interested in more articles about Operating Systems? Navigate to our Categories page using the bar on the left or check out these popular articles:

Popular tags within this category include: Linux, Windows, Apache, CentOS, Debian, Fedora, RedHat, and more.

Don’t see what you’re looking for? Use the search bar at the top to search our entire Knowledge Base.

 

The Hivelocity Difference

Seeking a better Dedicated Server solution? In the market for Private Cloud or Colocation services? Check out Hivelocity’s extensive list of products for great deals and offers.

With best-in-class customer service, affordable pricing, a wide-range of fully-customizable options, and a network like no other, Hivelocity is the hosting solution you’ve been waiting for.

Unsure which of our services is best for your particular needs? Call or live chat with one of our sales agents today and see the difference Hivelocity can make for you.

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: support@hivelocity.net. We are also available to you through our phone and live chat system 24/7/365.