Obtain a standard datetime format that works across locales
Source:R/standard_date_time.R
standard_date_time.RdThe 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"))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")
)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
)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()
)After that, it's "medium":
fdt(
input = "2018-07-04 22:05(America/Vancouver)",
format = standard_date_time(type = "medium")
)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")
)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")
)