ID EN
Miscellaneous

timezones

R Base 3.6.2

Information about time zones in R. Sys.timezone returns the name of the current time zone.

Syntax

R
Sys.timezone(location = TRUE)<p></p><p>OlsonNames(tzdir = NULL)</p>

Arguments

Parameter Description
location logical: defunct: ignored, with a warning for false values.
tzdir The time-zone database to be used: the default is to try known locations until one is found.

Return Value

Sys.timezone returns an OS-specific character string, possibly NA or an empty string (which on some OSes means UTC). This will be a location such as "Europe/London" if one can be ascertained. A time zone region may be known by several names: for example "Europe/London" is also known as GB, GB-Eire, Europe/Belfast, Europe/Guernsey, Europe/Isle_of_Man and Europe/Jersey. A few regions are also known by a summary of their time zone, e.g.PST8PDT is an alias for America/Los_Angeles. OlsonNames returns

Details

Time zones are a system-specific topic, but these days almost all R platforms use similar underlying code, used by Linux, macOS, Solaris, AIX and FreeBSD, and installed with R on Windows. (Unfortunately there are many system-specific errors in the implementations.) It is possible to use the R sources' version of the code on Unix-alikes as well as on Windows: this is the default for macOS and recommended for Solaris. It should be possible to set the current 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 initially (and on some OSes it is always set), otherwise it will try to retrieve from the OS a value which if set for TZ would give the initial time zone. (‘Initially’ means before any tim

Examples

Example
R
# NOT RUN {
Sys.timezone()

str(OlsonNames()) ## typically close to 600 hundred names,
## typically some acronyms/aliases such as "UTC", "NZ", "MET", "Eire", ..., but
## mostly pairs (and triplets) such as "Pacific/Auckland"
table(sl <- grepl("/", OlsonNames()))
OlsonNames()[ !sl ] # the simple ones
head(Osl <- strsplit(OlsonNames()[sl], "/"))
(tOS1 <- table(vapply(Osl, `[[`, "", 1))) # Continents, countries, ...
table(lengths(Osl))# most are pairs, some triplets
str(Osl[lengths(Osl) >= 3])# "America" South and North ...
# }

See Also

Sys.time as.POSIXlt. https://en.wikipedia.org/wiki/Time_zone and https://data.iana.org/time-zones/tz-link.html for extensive sets of links. https://data.iana.org/time-zones/theory.html for the ‘rules’ of the Olson/IANA database.