6

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?

  • /etc/locatime is generally used by redhat distros and /etc/timezone is generally used by debian distros. – Jesse_b Aug 9 '17 at 14:00
  • 1
    @Jesse_b No, this isn't a matter of distributions. Some applications use the one, others use the other. – Gilles Aug 9 '17 at 22:39
  • See also unix.stackexchange.com/questions/16190/… – Gilles Aug 9 '17 at 22:42
5

/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 systmes 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 when daylight-savings-time (if you're in an insane municipality that observes it) starts and ends and what offset that applies, as well as encoding the rules for leap day, and annotating how may leap seconds have been observed. This is what gets used by things like the date command (and it's 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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.