date

The date module is a flat convenience API for working with Unix timestamps (seconds since the epoch). All component extraction is done in UTC. Import it with import date.

Functions

FunctionSignatureDescription
nowdate.now() → stringcurrent time as an RFC3339 string
unixdate.unix() → intcurrent time in Unix seconds
parsedate.parse(s: string) → intparse an RFC3339 string into Unix seconds
formatdate.format(ts: int, layout: string) → stringformat a timestamp; layout is a Go layout or a shortcut: "date", "time", "datetime", "rfc3339", "rfc1123"
yeardate.year(ts: int) → intyear of the timestamp
monthdate.month(ts: int) → intmonth, 1–12
daydate.day(ts: int) → intday of month
hourdate.hour(ts: int) → inthour, 0–23
minutedate.minute(ts: int) → intminute, 0–59
seconddate.second(ts: int) → intsecond, 0–59
weekdaydate.weekday(ts: int) → stringweekday name, e.g. “Monday”
addDaysdate.addDays(ts: int, n: int) → inttimestamp n days later
addHoursdate.addHours(ts: int, n: int) → inttimestamp n hours later
addMinutesdate.addMinutes(ts: int, n: int) → inttimestamp n minutes later
diffdate.diff(ts1: int, ts2: int) → intseconds between two timestamps (ts2 − ts1)
isLeapYeardate.isLeapYear(year: int) → booltrue if the year is a leap year

Example

import date

let now = date.unix()
let tomorrow = date.addDays(now, 1)

print(date.format(now, "datetime"))       // 2026-05-29 14:03:21
print(date.weekday(tomorrow))             // Saturday
print(date.diff(now, tomorrow))           // 86400 seconds
Standard library · View as Markdown · llms-full.txt