change_time | R Documentation |
change_time
changes the time and time zone
without changing the time display.
change_time(time, tz = "")
time |
Time (as a scalar or vector).
If |
tz |
Time zone (as character string).
Default: |
change_time
expects inputs to time
to be local time(s) (of the "POSIXlt" class)
and a valid time zone argument tz
(as a string)
and returns the same time display (but different actual times)
as calendar time(s) (of the "POSIXct" class).
A calendar time of class "POSIXct".
change_tz
function which preserves time but changes time display;
Sys.time()
function of base R.
Other date and time functions:
change_tz()
,
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_time(as.POSIXlt(Sys.time()), tz = "UTC")
# from "POSIXlt" time:
t1 <- as.POSIXlt("2020-01-01 10:20:30", tz = "Europe/Berlin")
change_time(t1, "Pacific/Auckland")
change_time(t1, "America/Los_Angeles")
# from "POSIXct" time:
tc <- as.POSIXct("2020-07-01 12:00:00", tz = "UTC")
change_time(tc, "Pacific/Auckland")
# from "Date":
dt <- as.Date("2020-12-31", tz = "Pacific/Honolulu")
change_time(dt, tz = "Pacific/Auckland")
# from time "string":
ts <- "2020-12-31 20:30:45"
change_time(ts, tz = "America/Los_Angeles")
# from other "string" times:
tx <- "7:30:45"
change_time(tx, tz = "Asia/Calcutta")
ty <- "1:30"
change_time(ty, tz = "Europe/London")
# convert into local times:
(l1 <- as.POSIXlt("2020-06-01 10:11:12"))
change_tz(change_time(l1, "Pacific/Auckland"), tz = "UTC")
change_tz(change_time(l1, "Europe/Berlin"), tz = "UTC")
change_tz(change_time(l1, "America/New_York"), tz = "UTC")
# with vector of "POSIXlt" times:
(l2 <- as.POSIXlt("2020-12-31 23:59:55", tz = "America/Los_Angeles"))
(tv <- c(l1, l2)) # uses tz of l1
change_time(tv, "America/Los_Angeles") # change time and tz
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.