[R] List of all times zones in R
David Winsemius
dwinsemius at comcast.net
Mon Jan 31 14:45:16 CET 2011
On Jan 31, 2011, at 1:07 AM, Maithula Chandrashekhar wrote:
> Hi all, in R I have Sys.timezone() function to get the current working
> Time zone.
Only on some systems.
> However I want to have a vector to get the list of all
> available time zones, like say, LETTERS gives me all letters. Is there
> any function like that?
On a Mac (10.5.8) the timezone information is in /usr/share/timezone/
which also has a file named "zone.tab"
This is the header of that file:
> readLines("/usr/share/zoneinfo/zone.tab")
[1] "# <pre>"
[2] "# @(#)zone.tab\t8.28"
[3] "# This file is in the public domain, so clarified as of"
[4] "# 2009-05-17 by Arthur David Olson."
[5] "#"
[6] "# TZ zone descriptions"
[7] "#"
[8] "# From Paul Eggert (1996-08-05):"
[9] "#"
[10] "# This file contains a table with the following columns:"
[11] "# 1. ISO 3166 2-character country code. See the file
`iso3166.tab'."
[12] "# 2. Latitude and longitude of the zone's principal location"
[13] "# in ISO 6709 sign-degrees-minutes-seconds format,"
[14] "# either +-DDMM+-DDDMM or +-DDMMSS+-DDDMMSS,"
[15] "# first latitude (+ is north), then longitude (+ is east)."
[16] "# 3. Zone name used in value of TZ environment variable."
[17] "# 4. Comments; present if and only if the country has
multiple rows."
[18] "#"
[19] "# Columns are separated by a single tab."
[20] "# The table is sorted first by country, then an order within
the country that"
[21] "# (1) makes some geographical sense, and"
[22] "# (2) puts the most populous zones first, where that does not
contradict (1)."
[23] "#"
[24] "# Lines beginning with `#' are comments."
[25] "#"
[26] "#country-"
[27] "#code\tcoordinates\tTZ\t\t\tcomments"
[28] "AD\t+4230+00131\tEurope/Andorra"
snipped the remaining 400 lines
In addition in that directory, there are separate subdirectories for
each timezone and the number of such entries exceeded the number of
lines in zone.tab. Attached is a file with the names of the
subdirectories with the common stem removed produced by with this code
acting on a pasted screen scrape of a terminal session:
> TZlist <- strsplit(gsub("/usr/share/zoneinfo/", "", gsub("\\\n",
",", txt)), ",")
> write.table(TZlist, file="TZlist.txt")
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: TZlist.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110131/3d6c0953/attachment.txt>
-------------- next part --------------
This is its tail:
[570] "US/Alaska"
[571] "US/Aleutian"
[572] "US/Arizona"
[573] "US/Central"
[574] "US/East-Indiana"
[575] "US/Eastern"
[576] "US/Hawaii"
[577] "US/Indiana-Starke"
[578] "US/Michigan" # my birth state, its timezone rules seem to
change with every election.
[579] "US/Mountain"
[580] "US/Pacific"
[581] "US/Samoa"
[582] "UTC"
[583] "Universal"
[584] "W-SU"
[585] "WET"
[586] "Zulu" # which I seem to remember is a synonym for UTC
Sys.timezone doesn't actually produce useful information in all cases
(and this is documented behavior).
> Sys.timezone()
[1] ""
> Sys.getenv("TZ")
TZ
""
You can change the timezone on a Mac (and probably on other systems)
with Sys.setenv():
> Sys.time()
[1] "2011-01-31 08:35:17 EST"
> Sys.setenv("TZ"="US/Samoa")
> Sys.time()
[1] "2011-01-31 02:35:52 SST"
> Sys.setenv("TZ"="US/Eastern")
> Sys.time()
[1] "2011-01-31 08:37:07 EST"
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list