17

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?

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

2 Answers 2

17

/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.

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.