what_time | R Documentation |
what_time
provides a satisficing version of
Sys.time()
that is sufficient for most purposes.
what_time(when = NA, seconds = FALSE, as_string = TRUE, sep = ":", tz = "")
when |
Time (as a scalar or vector).
Default: |
seconds |
Boolean: Show time with seconds?
Default: |
as_string |
Boolean: Return as character string?
Default: |
sep |
Character: Separator to use.
Default: |
tz |
Time zone.
Default: |
By default, what_time
prints a simple version of
when
or Sys.time()
as a character string (in "
using current default system settings.
If as_string = FALSE
, a "POSIXct"
(calendar time) object is returned.
The tz
argument allows specifying time zones
(see Sys.timezone()
for current setting
and OlsonNames()
for options.)
However, tz
is merely used to represent the
times provided to the when
argument.
Thus, there currently is no active conversion
of times into other time zones
(see the now
function of lubridate package).
A character string or object of class "POSIXct".
cur_time()
function to print the current time;
cur_date()
function to print the current date;
now()
function of the lubridate package;
Sys.time()
function of base R.
Other date and time functions:
change_time()
,
change_tz()
,
cur_date()
,
cur_time()
,
days_in_month()
,
diff_dates()
,
diff_times()
,
diff_tz()
,
is_leap_year()
,
what_date()
,
what_month()
,
what_wday()
,
what_week()
,
what_year()
,
zodiac()
what_time()
# with vector (of "POSIXct" objects):
tm <- c("2020-02-29 01:02:03", "2020-12-31 14:15:16")
what_time(tm)
# with time zone:
ts <- ISOdate(2020, 12, 24, c(0, 12)) # midnight and midday UTC
t1 <- what_time(when = ts, tz = "Pacific/Honolulu")
t1 # time display changed, due to tz
# return "POSIXct" object(s):
# Same time in differen tz:
t2 <- what_time(as.POSIXct("2020-02-29 10:00:00"), as_string = FALSE, tz = "Pacific/Honolulu")
format(t2, "%F %T %Z (UTF %z)")
# from string:
t3 <- what_time("2020-02-29 10:00:00", as_string = FALSE, tz = "Pacific/Honolulu")
format(t3, "%F %T %Z (UTF %z)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.