change_tz | R Documentation |
change_tz
changes the nominal time zone (i.e., the time display)
without changing the actual time.
change_tz(time, tz = "")
time |
Time (as a scalar or vector).
If |
tz |
Time zone (as character string).
Default: |
change_tz
expects inputs to time
to be calendar time(s) (of the "POSIXct" class)
and a valid time zone argument tz
(as a string)
and returns the same time(s) as local time(s)
(of the "POSIXlt" class).
A local time of class "POSIXlt".
change_time
function which preserves time display but changes time;
Sys.time()
function of base R.
Other date and time functions:
change_time()
,
cur_date()
,
cur_time()
,
days_in_month()
,
diff_dates()
,
diff_times()
,
diff_tz()
,
is_leap_year()
,
what_date()
,
what_month()
,
what_time()
,
what_wday()
,
what_week()
,
what_year()
,
zodiac()
change_tz(Sys.time(), tz = "Pacific/Auckland")
change_tz(Sys.time(), tz = "Pacific/Honolulu")
# from "POSIXct" time:
tc <- as.POSIXct("2020-07-01 12:00:00", tz = "UTC")
change_tz(tc, "Australia/Melbourne")
change_tz(tc, "Europe/Berlin")
change_tz(tc, "America/Los_Angeles")
# from "POSIXlt" time:
tl <- as.POSIXlt("2020-07-01 12:00:00", tz = "UTC")
change_tz(tl, "Australia/Melbourne")
change_tz(tl, "Europe/Berlin")
change_tz(tl, "America/Los_Angeles")
# from "Date":
dt <- as.Date("2020-12-31")
change_tz(dt, "Pacific/Auckland")
change_tz(dt, "Pacific/Honolulu") # Note different date!
# with a vector of "POSIXct" times:
t2 <- as.POSIXct("2020-12-31 23:59:55", tz = "America/Los_Angeles")
tv <- c(tc, t2)
tv # Note: Both times in tz of tc
change_tz(tv, "America/Los_Angeles")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.