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 = "")
Time (as a scalar or vector).
Default: when = NA
.
Returning Sys.time()
, if when = NA
.
Boolean: Show time with seconds?
Default: seconds = FALSE
.
Boolean: Return as character string?
Default: as_string = TRUE
.
If as_string = FALSE
, a "POSIXct" object is returned.
Character: Separator to use.
Default: sep = ":"
.
Time zone.
Default: tz = ""
(i.e., current system time zone,
see Sys.timezone()
).
Use tz = "UTC"
for Coordinated Universal Time.
A character string or object of class "POSIXct".
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).
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()
,
is_leap_year()
,
what_date()
,
what_day()
,
what_month()
,
what_week()
,
what_year()
# NOT RUN {
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 = "US/Hawaii")
t1
# return "POSIXct" object(s):
t2 <- what_time("2020-02-29 12:30:45", as_string = FALSE, tz = "US/Hawaii")
format(t2, "%T %Z (UTF %z)")
# }
Run the code above in your browser using DataLab