# A fixed moment: the output stays the same
moment <- as.POSIXct("2027-01-01 22:13:20",
tz = "UTC")
# %I is the 12-hour clock, %p is AM/PM
short_style <- format(moment, "%m/%d/%y %I:%M %p")
# short_style = 01/01/27 10:13 PM
custom_style <- format(moment, "%Y-%m-%d")
# custom_style = 2027-01-01
# No format: the date, a space, the time
standard_style <- format(moment)
# standard_style = 2027-01-01 22:13:20
# ISO 8601: "T" between date and time
iso_style <- format(moment, "%Y-%m-%dT%H:%M:%S")
# iso_style = 2027-01-01T22:13:20
# Inside a sentence, the same codes
str_format <- paste("Today",
format(moment, "%d %B"))
# str_format = Today 01 January
cat("short_style =", short_style, "\n")
cat("custom_style =", custom_style, "\n")
cat("standard_style =", standard_style, "\n")
cat("iso_style =", iso_style, "\n")
cat("str_format =", str_format, "\n")