force_tz returns a the date-time that has the same clock time as x in the new time zone. Although the new date-time has the same clock time (e.g. the same values in the year, month, days, etc. elements) it is a different moment of time than the input date-time. force_tz defaults to the Universal Coordinated time zone (UTC) when an unrecognized time zone is inputted. See Sys.timezone() for more information on how R recognizes time zones.

force_tz(time, tzone = "", roll = FALSE)

Arguments

time

a POSIXct, POSIXlt, Date, chron date-time object, or a data.frame object. When a data.frame all POSIXt elements of a data.frame are processed with force_tz() and new data.frame is returned.

tzone

a character string containing the time zone to convert to. R must recognize the name contained in the string as a time zone on your system.

roll

logical. If TRUE, and time falls into DST skip assume the next valid civil time, otherwise return NA. See examples.

Value

a POSIXct object in the updated time zone

See also

with_tz()

Examples

x <- ymd_hms("2009-08-07 00:00:01", tz = "America/New_York") force_tz(x, "UTC")
#> [1] "2009-08-07 00:00:01 UTC"
force_tz(x, "Europe/Amsterdam")
#> [1] "2009-08-07 00:00:01 CEST"
## DST skip: y <- ymd_hms("2010-03-14 02:05:05 UTC") force_tz(y, "America/New_York", roll=FALSE)
#> [1] NA
force_tz(y, "America/New_York", roll=TRUE)
#> [1] "2010-03-14 03:00:00 EDT"