What's the difference between localtime and timezone files?

6,619

Solution 1

/etc/timezone is a text-based representation of what timezone you are in. This could be expressed as an offset from GMT/UTC, but more often it's the path under /usr/share/zoneinfo that points to the appropriate timezone data file (for example, if you're in most places in the Eastern US, this will be America/New_York or US/Eastern). The main purpose of this is to make sure that /etc/localtime gets updated correctly when the data files in /usr/share/zoneinfo are updated (although some systems make /etc/localtime a symbolic link pointing to the correct file there) and to provide a quick user-friendly name for the timezone (US/Eastern is a lot more user friendly than EST or EDT). Only some systems actually use this file.

/etc/localtime is a binary representation of the exact rules for calculating the time relative to UNIX time (the internal representation used by the kernel, which is measured as seconds since 1970-01-01 00:00:00 UTC). This includes things like the normal offset from UTC, as well as the rules for daylight saving time (when it starts and ends and what offset it applies), as well as the rules for leap day, and annotating how many leap seconds have been observed. This gets used by things like the date command (and its equivalent functions in various programming languages) to show you exactly what time it is locally. All Linux systems with a conventional userspace use this file.

Solution 2

Timezone tells your system where you are in the world. i.e. GMT-4 or GMT+2 (depending on your exact location on the planet).

Localtime tells your system exactly what time it is at your location.

Share:
6,619

Related videos on Youtube

CarlosAS
Author by

CarlosAS

Updated on September 18, 2022

Comments

  • CarlosAS
    CarlosAS over 1 year

    I'm setting up a docker container and there are two places where the timezone are set:

    • /etc/localtime
    • /etc/timezone

    Can anybody explain me what's the difference between them and what are both used for?

    • jesse_b
      jesse_b almost 7 years
      /etc/locatime is generally used by redhat distros and /etc/timezone is generally used by debian distros.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' almost 7 years
      @Jesse_b No, this isn't a matter of distributions. Some applications use the one, others use the other.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' almost 7 years