Sys.timezone()
windows
tzfile <- file.path(R.home("share"), "zoneinfo", "zone.tab")
tzones <- read.delim(tzfile, row.names = NULL, header = FALSE,
col.names = c("country", "coords", "name", "comments"),
as.is = TRUE, fill = TRUE, comment.char = "#")
str(tzones$name)
unix
## need to find a suitable file path (if any) for your system
tzdirs <- c("/usr/share/zoneinfo", # Linux, OS X, FreeBSD
"/usr/lib/zoneinfo", # early glibc
"/usr/share/lib/zoneinfo", # AIX?
"/usr/local/etc/zoneinfo", # tzcode default
"/etc/zoneinfo", "/usr/etc/zoneinfo")
tzfiles <- c(file.path(tzdirs, "zone.tab"),
"/usr/share/lib/zoneinfo/tab/zone_sun.tab") # Solaris
if (any(have <- file.exists(tzfiles))) {
tzfile <- tzfiles[have][1]
tzones <- read.delim(tzfile, row.names = NULL, header = FALSE,
col.names = c("country", "coords", "name", "comments"),
as.is = TRUE, fill = TRUE, comment.char = "#")
str(tzones$name)
}
## Try to find the system's internal name for the current time zone.
if(nzchar(lt <- Sys.getenv("TZ"))) { # always set on Solaris, AIX
print(lt)
} else {
lt <- normalizePath("/etc/localtime") # Linux, OS X, ...
if (grepl(pat <- "^/usr/share/zoneinfo/", lt))
print(sub(pat, "", lt))
}
Run the code above in your browser using DataLab