# Time zones differences:
tm <- "2020-01-01 01:00:00" # nominal time
t1 <- as.POSIXct(tm, tz = "NZ")
t2 <- as.POSIXct(tm, tz = "Europe/Berlin")
t3 <- as.POSIXct(tm, tz = "US/Hawaii")
# as character (in "HH:MM"):
diff_tz(t1, t2)
diff_tz(t2, t3)
diff_tz(t1, t3)
# as numeric (in minutes):
diff_tz(t1, t3, in_min = TRUE)
# Compare local times (POSIXlt):
t4 <- as.POSIXlt(Sys.time(), tz = "NZ")
t5 <- as.POSIXlt(Sys.time(), tz = "Europe/Berlin")
diff_tz(t4, t5)
diff_tz(t4, t5, in_min = TRUE)
# DSL shift: Spring ahead (on 2020-03-29: 02:00:00 > 03:00:00):
s6 <- "2020-03-29 01:00:00 CET" # before DSL switch
s7 <- "2020-03-29 03:00:00 CEST" # after DSL switch
t6 <- as.POSIXct(s6, tz = "Europe/Berlin") # CET
t7 <- as.POSIXct(s7, tz = "Europe/Berlin") # CEST
diff_tz(t6, t7) # 1 hour forwards
diff_tz(t6, t7, in_min = TRUE)
Run the code above in your browser using DataLab