Sys.timezone
returns
the name of the current time zone.
Sys.timezone(location = TRUE)
OlsonNames()
Sys.timezone
returns an OS-specific character string, possibly
NA
or an empty string (which on some OSes means UTC).
For the default location = TRUE
this will be a location such as
"Europe/London"
if one can be ascertained. For location
= FALSE
this may be an abbreviation such as "EST"
or
"CEST"
on Windows.OlsonNames
returns a character vector.
tzset
can be helpful, but it can also be
inaccurate. There is a cumbersome POSIX specification (listed under
environment variable TZ at
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08),
which is often at least partially supported, but there are other more
user-friendly ways to specify time zones. Almost all R platforms make use of a time-zone database originally
compiled by Arthur David Olson and now managed by IANA, in which the
preferred way to refer to a time zone is by a location (typically of a
city) e.g. Europe/London
, America/Los_Angeles
,
Pacific/Easter
. Some traditional designations are also allowed
such as EST5EDT
or GB
. (Beware that some of these
designations may not be what you expect: in particular EST
is a
time zone used in Canada without daylight saving time, and not
EST5EDT
nor (Australian) Eastern Standard Time.) The
designation can also be an optional colon prepended to the path to a
file giving complied zone information (and the examples above are all
files in a system-specific location). See
http://www.twinsun.com/tz/tz-link.htm for more details and
references. By convention, regions with a unique time-zone history
since 1970 have specific names in the database, but those with
different earlier histories may not. Each time zone has one or two
(the second for DST) abbreviations used when formatting times. The abbreviations used have changed over the years: for example France
used PMT (Paris Mean Time) from 1891 to 1911 then
WET/WEST up to 1940 and CET/CEST from 1946. (In almost
all time zones they have been stable since 1970.) The POSIX standard
allows only one or two abbreviations per time zone, so you may see the
current abbreviation(s) used for older times: more so in versions of
R prior to 3.1.0. The function OlsonNames
returns the time-zone names known to
the Olson/IANA database on the current system. The system-specific
location in the file system varies, e.g. /usr/share/zoneinfo
(Linux, OS X, FreeBSD), /usr/share/lib/zoneinfo (Solaris, AIX),
.... It is likely that there is a file named something like
zone.tab under that directory listing the locations known as
time-zone names (but not for example EST5EDT
): this is read by
OlsonNames
. See also
http://en.wikipedia.org/wiki/Zone.tab.
unix Where R was configured with option --with-internal-tzcode
(the default on OS X: recommended on Solaris), the database at
file.path(R.home("share"), "zoneinfo")
is used by default: file
VERSION in that directory states the version. Environment
variable TZDIR can be used to point to a different
zoneinfo directory (this is also supported by some OSes,
e.g. Linux).
windows Under Windows the current version of the database is stated in
file R_HOME\share\zoneinfo\VERSION.
Environment variable TZDIR can be used to point to a different
zoneinfo directory. An attempt is made (once only per session) to map Windows' idea of the
current time zone to a location, following an earlier version of
http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
It can be overridden by setting the TZ environment variable
before any date-times are used in the session. Windows documents a specification of the form GST-1GDT
: this is
interpreted as POSIX-like and hence the US rules for changing
to/from DST are applied (and are incorrect for Germany). This is
accepted for backwards compatibility but is unreliable and gives a
warning. Most platforms support time zones of the form GMT+n and
GMT-n, which assume at a fixed offset from UTC (hence no DST).
Contrary to some expectations (but consistent with names such as
PST8PDT), negative offsets are times ahead of (east of) UTC,
positive offsets are times behind (west of) UTC. Immediately prior to the advent of legislated time zones, people used
time based on their longitude, known as Local Mean Time and
abbreviated as LMT in the databases. Often this was codified
by a name such as Copenhagen Mean Time for a period before
the switch to standard time zones (such as GMT+5). For
example, Paris codified its LMT as Paris Mean Time in 1891,
switched to GMT+0 in 1911 and to GMT-1 in 1945. It should be possible to set the time zone via the environment
variable TZ: see the section on Time zone names for
suitable values. Sys.timezone()
will return the value of
TZ if set (and on some OSes it is always set), otherwise it will
try to retrieve a value which if set for TZ would give the
current time zone. This is not in general possible, and
Sys.timezone(FALSE)
on Windows will retrieve the abbreviation
used for the current time.
If TZ is set but empty or invalid, most platforms default to UTC, the time zone colloquially known as GMT (see http://en.wikipedia.org/wiki/Coordinated_Universal_Time). (Some but not all platforms will give a warning for invalid timezones.)
Time zones did not come into use until the second half of the
nineteenth century and were not widely adopted until the twentieth,
and daylight saving time (DST, also known as summer
time) was first introduced in the early twentieth century, most
widely in 1916. Over the last 100 years places have changed their
affiliation between major time zones, have opted out of (or in to) DST
in various years or adopted DST rule changes late or not at all.
The most common system implementation of POSIXct
is as signed
32-bit integers and so only goes back to the end of 1901: on such
systems R assumes that dates prior to that are in the same time zone
as they were in 1902. Most of the world had not adopted time zones by
1902 (so used local mean time based on longitude) but for
some places there had been time-zone changes before then. 64-bit
representations are becoming common; unfortunately on some 64-bit OSes
(notably OS X) the database information is only available for the
range 1901--2038, and incompletely for the end years.
Sys.time
, as.POSIXlt
.http://en.wikipedia.org/wiki/Time_zone and http://www.twinsun.com/tz/tz-link.htm for extensive sets of links.
Sys.timezone()
str(OlsonNames()) ## a few hundred names
Run the code above in your browser using DataLab