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

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

-- A fixed moment: the output stays the same
local moment = 1798841600

-- "!" is UTC, %I is the 12-hour clock,
-- %p is AM/PM
local short_style =
  os.date("!%m/%d/%y %I:%M %p", moment)
-- short_style = 01/01/27 10:13 PM

local custom_style = os.date("!%Y-%m-%d", moment)
-- custom_style = 2027-01-01

-- %F is %Y-%m-%d, %T is %H:%M:%S
local standard_style = os.date("!%F %T", moment)
-- standard_style = 2027-01-01 22:13:20

-- ISO 8601: "T" between date and time
local iso_style = os.date("!%FT%T", moment)
-- iso_style = 2027-01-01T22:13:20

-- %c is the style used when there is no format
local default_style = os.date("!%c", moment)
-- default_style = Fri Jan  1 22:13:20 2027

-- Inside a sentence, the same codes
local str_format =
  "Today " .. os.date("!%d %B", moment)
-- str_format = Today 01 January

print("short_style = " .. short_style)
print("custom_style = " .. custom_style)
print("standard_style = " .. standard_style)
print("iso_style = " .. iso_style)
print("default_style = " .. default_style)
print("str_format = " .. str_format)

-- An unknown code is an error
local ok, err = pcall(os.date, "%Q", moment)
-- ok = false
-- err = bad argument #1 to 'os.date' (invalid
-- conversion specifier '%Q')
print("ok = " .. tostring(ok))
print("err = " .. err)