Skip to main content

date

Function date 

Source
pub fn date(format: option<string>, time: option<number>) -> any
Expand description

Formats a date and time.

§Parameters

  • format: a format string following the ISO C function strftime (default "%c", the full date and time). A leading "!" formats in UTC instead of local time. The special format "*t" (or "!*t") requests a table instead of a string.
  • time: the time to format, as returned by time (default: the current time).

§Return value

A string with the formatted date, or, for the "*t" formats, a table with fields year, month (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61 due to leap seconds), wday (weekday, 1–7, Sunday is 1), yday (day of the year, 1–366), and isdst (daylight saving flag, a boolean).

§Examples

print(os.date("%Y-%m-%d"))          --> 2026-09-03
print(os.date("!%H:%M UTC"))        --> 18:45 UTC
local t = os.date("*t")
print(t.year, t.month, t.day)       --> 2026   9   3

§See also

time, difftime