29

A quick google search seems to get me nowhere. What are valid time zones in lubridate's tz option? In particular, am looking for Brasilia's time zone. Thanks!

library(lubridate)
dts <- c("6-3-1995 12:01:01","29-3-1995 23:01:01","29-3-1995 20:01:01")
dmy_hms(dts)               # locale's tz default
dmy_hms(dts, tz = "chile") # Chilean time (has one time zone only)
emagar
  • 813
  • 1
  • 11
  • 23

1 Answers1

39

Take a search through the OlsonNames() in the standard base R package, which provides a list of all the valid timezones on the host system. e.g.:

grep("Brazil", OlsonNames(), value=TRUE)

...provides four possible results for Brazil.

thelatemail
  • 81,120
  • 12
  • 111
  • 172
  • I am a Brazilian and I find this particularly trick... now it 11:40 pm, and I am in the Brazil/East region, and when run lubridate's now(tz = "Brazil/East") it is one hour ahead, in the next day. "2021-02-15 00:41:27 -02" – Marcio Rodrigues Feb 15 '21 at 02:39
  • I think it could be related to daylight saving time, a witch no longer exists in Brazil anymore. – Marcio Rodrigues Feb 15 '21 at 02:44
  • 1
    @MarcioRodrigues - if you know how many hours +/- from GMT/UTC you are in your current location, you can use that timezone without any daylight savings consideration. E.g. try `now(tz="Etc/GMT+3")` maybe? – thelatemail Feb 15 '21 at 02:58
  • That is correct and helpful. I also found other Brazilian cities in OlsonNames(), under "America/city" names. "America/Recife" is set to GMT -03. – Marcio Rodrigues Feb 15 '21 at 16:09
  • `grep("America", OlsonNames(), value=TRUE)` – Marcio Rodrigues Feb 15 '21 at 16:10
  • If you just want to show it in the timezone of your system, you can use `tz = Sys.timezone()`. – Chris Middleton Apr 08 '21 at 16:25