what_time {ds4psy}R Documentation

What time is it?

Description

what_time provides a satisficing version of Sys.time() that is sufficient for most purposes.

Usage

what_time(when = NA, seconds = FALSE, as_string = TRUE, sep = ":", tz = "")

Arguments

when

Time (as a scalar or vector). Default: when = NA. Returning Sys.time(), if when = NA.

seconds

Boolean: Show time with seconds? Default: seconds = FALSE.

as_string

Boolean: Return as character string? Default: as_string = TRUE. If as_string = FALSE, a "POSIXct" object is returned.

sep

Character: Separator to use. Default: sep = ":".

tz

Time zone. Default: tz = "" (i.e., current system time zone, see Sys.timezone()). Use tz = "UTC" for Coordinated Universal Time.

Details

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).

Value

A character string or object of class "POSIXct".

See Also

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()

Examples

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)")


[Package ds4psy version 1.0.0 Index]