Change the Timezone in Linux

Whether you’re a new user or a seasoned terminal expert, you can easily change the timezone of your Linux computer. There are three main ways to change the timezone settings in Linux; one uses the desktop and the other two are executed through the command line. Follow this guide to learn all of them.

Steps

Using the Graphical User Interface

  1. Click on the System menu and select Administration. Select the Time and Date option.
    • Alternatively, you can click on the clock and select Time and Date settings from the menu.
    • This method is for Ubuntu. The menu options are similar for most Linux distributions.[1]
  2. Click your currently selected timezone. Depending on your distribution, you may have to select a timezone tab first.
  3. Select your location on the world map. Most every distribution will have a graphic map that you can use to select your location. This will help narrow down the correct timezone for you.
    • After selecting your general location, select the closest city.

Using the Timezone Selection Menu

  1. Open the terminal. This method will open an ASCII menu that will allow you to choose your timezone. Enter the following command based on the Linux distribution you are using:
    • Ubuntu: dpkg-reconfigure tzdata
    • Redhat: redhat-config-date
    • CentOS/Fedora: system-config-date
    • FreeBSD/Slackware: tzselect
  2. Select your timezone. Each distribution will open a slightly different menu, but all generally perform the same function. Navigate to the region and city that best matches your location and select it. This will change the timezone on your system.[2]

Using the Command Line

  1. Check your current timezone. Log in as root. Open the terminal and check which timezone your machine is currently using by executing the date command. The terminal will display the date in the following format: Mon Aug 12 12:15:08 PST 2013. PST in this case refers to the current timezone (Pacific Standard Time).
  2. Select your timezone region. Change to the directory /usr/share/zoneinfo. A list of time zone regions will be displayed. Choose the most appropriate region by pressing the corresponding number.
    • The /usr/share/zoneinfo directory may vary depending on your Linux distribution.
  3. Backup your old timezone settings. If you wish, backup the previous timezone configuration by renaming it to a backup name. Use the following command mv /etc/localtime /etc/localtime-old
  4. Link your machine’s clock to a city in your timezone. Use the following command, replacing the region and city with your appropriate entries: ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime [3]
    • If your city is not listed in the timezone list, pick one from your same timezone.
  5. Verify that your timezone has been set. Run the date command again and check that the timezone corresponds to the one you just changed to.
  6. Set your clock to stay synced with internet time servers. Most modern distributions have NTP already installed. If you do not, you will need to install the NTP server package. Use the following commands to install it, depending on your Linux distribution:
    • Ubuntu/Debian: sudo aptitude install ntp
    • CentOS: sudo yum install ntp
      sudo /sbin/chkconfig ntpd on
    • Fedora/RedHat: sudo yum install ntp
      sudo chkconfig ntpd on
    • Enter the ntpdate command: ntpdate
    • There are a variety of public time servers available to connect to. You can find listings online.[4]

Tips

  • On RedHat Linux there is a utility called "Setup" that allows one to select the timezone from a list, but you must have installed the 'redhat-config-date' package. < note... on RHEL5 it is actually 'system-config-date' >
  • To setup UTC :
  • The time server parameter for rdate can be any public server that supports the RFC-868 time protocol. A list of public RFC-868 servers can be found at [1]. Note: As of April 2007, NIST announced it would phase out support for RFC-868 (scroll to the bottom of [2] to see the announcement). This has not happened as of April 2009).
  • On some versions of RedHat Linux, Slackware, Gentoo, SuSE, Debian, Ubuntu, and anything else that is "normal", the command to display and change the time is 'date', not 'clock'
  • On mobile phones and other small devices that run Linux, the time zone is stored differently. It is written in /etc/TZ, in the format that is described, for instance, in [3]. Edit this file manually or use echo (for instance, echo GMT0BST > /etc/TZ to set the the timezone of the United Kingdom).
  • vi /etc/sysconfig/clock and change the UTC line to: "UTC=true"
  • On systems that use dpkg (for example Debian and Ubuntu/Kubuntu), you should try "sudo dpkg-reconfigure tzdata". This will set up everything correctly in very few, simple steps.
  • The KNOPPIX live CD's persistent image removes a symbolic link on reboot, so the otherwise perfect example fails on reboot:
    <code>ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
    # symbolic link /etc/localtime is removed on reboot</code>
    • The proper way is on the boot command line as shown:
      <code>boot: knoppix tz=america/newyork</code>
    • Using a true copy command:
      <code>cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime</code>
      creates a persistent /etc/localtime file stored in the underlying /KNOPPIX-DATA/etc/localtime filesystem.
  • The /sbin/hwclock program retrieves and sets the BIOS clock. The BIOS clock or "Real Time Clock" is battery backed up and keeps the date and time when the computer is powered down. This clock is best kept in UTC, but is often kept in localtime. The clock may drift and can be periodically readjusted using the hwclock program.

Warnings

  • Some applications (such as PHP) have separate timezone settings from the system timezone.
  • On some systems, there is a system utility provided that will prompt for the correct timezone and make the proper changes to the system configuration. For example, Debian provides the "tzsetup" or "tzconfig" utility.
  • When updating a Virtual Server, rely on the hardware clock to be accurate rather than attempting to update it or use NTP. Attempts to update the hwclock or use NTP will fail because the Virtual Server cannot modify the actual hardware clock.

Related Articles

Sources and Citations