What's the difference between localtime and timezone files?
I’m setting up a docker container and there are two places where the timezone are set:
Can anybody explain me what’s the difference between them and what are both used for?
Timezone tells your system where you are in the world. i.e.
GMT+2 (depending on your exact location on the planet).
Localtime tells your system exactly what time it is at your location.
/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
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
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.