standard_date_time {bigD} | R Documentation |
Obtain a standard datetime format that works across locales
Description
The standard_date_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 datetime. The type
value is a keyword that
represents precision and verbosity; the available keywords are "short"
(the
default), "medium"
, "long"
, and "full"
.
Usage
standard_date_time(type = c("short", "medium", "long", "full"))
Arguments
type |
One of four standardized types for the resulting datetime 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 the date and time in a standardized way with standard_date_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_date_time(type = "full") )
#> [1] "Wednesday, July 4, 2018 at 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_date_time(type = "full"), locale = fdt_locales_lst$nl )
#> [1] "woensdag 4 juli 2018 om 22:05:00 Pacific-zomertijd"
We can use different type
values to control the output datetime string. The
default is "short"
.
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_date_time() )
#> [1] "7/4/18, 10:05 PM"
After that, it's "medium"
:
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_date_time(type = "medium") )
#> [1] "Jul 4, 2018, 10:05:00 PM"
The "short"
and "medium"
types don't display time zone information in the
output. Beginning with "long"
, the tz is shown.
fdt( input = "2018-07-04 22:05(America/Vancouver)", format = standard_date_time(type = "long") )
#> [1] "July 4, 2018 at 10:05:00 PM PDT"
If you don't include time zone information in the input, the "UTC"
time
zone will be assumed:
fdt( input = "2018-07-04 22:05", format = standard_date_time(type = "full") )
#> [1] "Wednesday, July 4, 2018 at 10:05:00 PM GMT+00:00"