Valid time zones in lubridate
Asked Answered
I

1

35

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)
Inch answered 21/4, 2015 at 22:29 Comment(2)
Take a search through OlsonNames() - e.g.: grep("Brazil",OlsonNames(),value=TRUE)Diagnostician
Brilliant @thelatemail! This narrows down the options. I presume that "Brazil/East" is the correct one...Inch
D
48

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.

Diagnostician answered 22/4, 2015 at 21:17 Comment(7)
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"Boddie
I think it could be related to daylight saving time, a witch no longer exists in Brazil anymore.Boddie
@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?Diagnostician
That is correct and helpful. I also found other Brazilian cities in OlsonNames(), under "America/city" names. "America/Recife" is set to GMT -03.Boddie
grep("America", OlsonNames(), value=TRUE)Boddie
If you just want to show it in the timezone of your system, you can use tz = Sys.timezone().Brownstone
Neat. Was looking for this. Immense helpDing

© 2022 - 2024 — McMap. All rights reserved.