Преобразование в строку

Простые типы / Дата и время

# Фиксированный момент: вывод не меняется
moment <- as.POSIXct("2027-01-01 22:13:20",
                     tz = "UTC")

# %I - 12-часовой формат, %p - 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

# Без формата: дата, пробел, время
standard_style <- format(moment)
# standard_style = 2027-01-01 22:13:20

# ISO 8601: "T" между датой и временем
iso_style <- format(moment, "%Y-%m-%dT%H:%M:%S")
# iso_style = 2027-01-01T22:13:20

# Внутри предложения те же коды
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")