standard_time {bigD} | R Documentation |
Obtain a standard time format that works across locales
Description
The standard_time()
function can be invoked in the format
argument of the
fdt()
function to help generate a locale-specific formatting string of a
certain 'type' of formatted time. The type
value is a keyword that
represents precision and verbosity; the available keywords are "short"
(the
default), "medium"
, "long"
, and "full"
.
Usage
standard_time(type = c("short", "medium", "long", "full"))
Arguments
type |
One of four standardized types for the resulting time that range
in precision and verbosity. These are |
Value
A vector of class date_time_pattern
.
Examples
With an input datetime of "2018-07-04 22:05(America/Vancouver)"
, we can
format as a time in a standardized way with standard_time()
providing the
correct formatting string. This function is invoked in the format
argument
of fdt()
:
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_time(type = "full") )
#> [1] "10:05:00 PM Pacific Daylight Time"
The locale can be changed and we don't have to worry about the particulars of the formatting string (they are standardized across locales).
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_time(type = "full"), locale = fdt_locales_lst$nl )
#> [1] "22:05:00 Pacific-zomertijd"
We can use different type
values to control the output date string. The
default is "short"
.
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_time() )
#> [1] "10:05 PM"
After that, it's "medium"
:
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_time(type = "medium") )
#> [1] "10:05:00 PM"
Then, "long"
:
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_time(type = "long") )
#> [1] "10:05:00 PM PDT"
And finally up to "full"
, which was demonstrated in the first example.