Skip to content

time

Dates and times: reading the clock, and rendering an instant.

An instant is a whole number of seconds since 1970-01-01 00:00:00, and every date and time is in UTC on every host.

import time

COMPACT

COMPACT: String = "yyyyMMddHHmmss"

The format string for a date and a time with nothing between the fields, as in 20261004123000, which sorts in time order as text.

Example

DATE

DATE: String = "yyyy-MM-dd"

The format string for a date alone, as in 2026-10-04.

Example

DATETIME

DATETIME: String = "yyyy-MM-dd HH:mm:ss"

The format string for a date and a time separated by a space, as in 2026-10-04 12:30:00.

Example

ISO8601

ISO8601: String = "yyyy-MM-ddTHH:mm:ssZ"

The format string for ISO 8601, as in 2026-10-04T12:30:00Z.

Example

TIME

TIME: String = "HH:mm:ss"

The format string for a time of day alone, as in 12:30:00.

Example

format

def format(t: (Int, Int, Int, Int, Int, Int), fmt: String) -> String

Writes a date and time as text, following the pattern fmt. In fmt, yyyy is the year, MM the month, dd the day, HH the hour, mm the minute and ss the second, each padded with zeros. The characters - : / . ,, a space, T and Z are copied as they are. Any other character ends the text there.

Parameters

  • t: (year, month, day, hour, minute, second), as now and of_instant answer.
  • fmt: the pattern; ISO8601, DATE, TIME, DATETIME and COMPACT are ready-made ones.

Returns

The formatted text.

Example

instant

def instant() -> Int

Reads the clock.

Returns

The current time as whole seconds since 1970-01-01 00:00:00 UTC.

Example

now

def now() -> (Int, Int, Int, Int, Int, Int)

Reads the clock once and splits it into a date and a time of day, in UTC.

Returns

(year, month, day, hour, minute, second), with the month 1 to 12 and the day 1 to 31.

Example

of_instant

def of_instant(t: Int) -> (Int, Int, Int, Int, Int, Int)

Splits an instant into a date and a time of day, in UTC.

Parameters

  • t: seconds since 1970-01-01 00:00:00 UTC, as instant answers.

Returns

(year, month, day, hour, minute, second), with the month 1 to 12 and the day 1 to 31.

Example