std/time/datetime
std/datetime — calendar-aware time formatting and parsing, in pure Axle.
Operates on i64 millis-since-epoch (compatible with std/time::instantNow
and std/sys::now), always in UTC. The calendar is Howard Hinnant's
proleptic Gregorian civil_from_days / days_from_civil, so a date before
the epoch decomposes as correctly as one after it. That rests on floor
division: Axle's / and % truncate toward zero, which would put-1 ms on 1970-01-01 instead of 1969-12-31.
Free functions
| Type | Method and description |
|---|---|
| formatIso8601(millis : i64) : string UTC instant millis as ISO-8601, e.g. "2026-05-10T14:23:45.123Z". |
| formatDate(millis : i64) : string UTC date of millis as "YYYY-MM-DD", e.g. "2026-05-10". |
| formatTime(millis : i64) : string UTC time of millis as "HH:MM:SS", e.g. "14:23:45". |
| formatHttpDate(millis : i64) : string UTC instant millis as an RFC 7231 HTTP date, e.g."Sun, 10 May 2026 14:23:45 GMT". |
| yearOf(millis : i64) : i32 UTC calendar year of millis. |
| monthOf(millis : i64) : i32 UTC month of millis, 1..12 (1 = January). |
| dayOf(millis : i64) : i32 UTC day of month of millis, 1..31. |
| hourOf(millis : i64) : i32 UTC hour of millis, 0..23. |
| minuteOf(millis : i64) : i32 UTC minute of millis, 0..59. |
| secondOf(millis : i64) : i32 UTC second of millis, 0..59. |
| millisecondOf(millis : i64) : i32 Sub-second millisecond component of millis, 0..999. |
| dayOfWeek(millis : i64) : i32 UTC day of week of millis: 0 = Sunday … 6 = Saturday. |
| buildEpochMillis(
year : i32,
month : i32,
day : i32,
hour : i32,
minute : i32,
second : i32,
millis : i32
) : i64 Composes UTC calendar components into milliseconds since the Unix epoch. An out-of-range component carries into the next unit (month 13 is January of the following year). |
| parseIso8601(s : string) : i64 Parses "YYYY-MM-DDTHH:MM:SS[.fff][Z]" (a space may stand for the T)into milliseconds since the Unix epoch (UTC). A fraction keeps its first three digits; anything after the optional Z is refused. A componentoutside its range is not rejected — it carries into the next unit, as buildEpochMillis documents — so "2026-13-01" names January 2027. |
| __dtFormatIso(millis : i64) : string |
| __dtFormatDate(millis : i64) : string |
| __dtFormatTime(millis : i64) : string |
| __dtPad(v : i64, width : i32) : string Decimal v zero-padded to width characters, the sign counted in the width. |
| __dtDayName(weekday : i32) : string |
| __dtMonthName(month : i32) : string |
| __dtZero() : i32 |
| __dtIsDigit(b : i32) : bool |
| __dtDigits(s : string, start : i64, count : i64) : i64 The count ASCII digits of s from start as a number, or -1 on any non-digit. |
| __dtParseFailure(s : string) : string |
| __dtMsPerMinute() : i64 |
| __dtMsPerHour() : i64 |
| __dtMsPerDay() : i64 |
| __dtFloorDiv(a : i64, b : i64) : i64 a / b rounded toward negative infinity, for a positive b. |
| __dtFloorMod(a : i64, b : i64) : i64 a mod b in 0..b, for a positive b. |
| __dtDays(millis : i64) : i64 Whole days from the epoch to the UTC day holding millis. |
| __dtMillisOfDay(millis : i64) : i64 |
| __dtEra(days : i64) : i64 |
| __dtDayOfEra(days : i64) : i64 Day of the 400-year era, 0..146096. |
| __dtYearOfEra(dayOfEra : i64) : i64 Year of the era, 0..399. |
| __dtDayOfMarchYear(days : i64) : i64 Day of the March-based year, 0..365. |
| __dtMarchMonth(dayOfYear : i64) : i64 Month of the March-based year, 0 = March … 11 = February. |
| __dtMonthOfDays(days : i64) : i32 |
| __dtDayOfDays(days : i64) : i32 |
| __dtYearOfDays(days : i64) : i64 |
| __dtDaysFromCivil(year : i64, month : i64, day : i64) : i64 |
Method detail
#formatIso8601
UTC instant millis as ISO-8601, e.g. "2026-05-10T14:23:45.123Z".
millis instant, milliseconds since the Unix epoch (UTC)#formatDate
UTC date of millis as "YYYY-MM-DD", e.g. "2026-05-10".
millis instant, milliseconds since the Unix epoch (UTC)#formatTime
UTC time of millis as "HH:MM:SS", e.g. "14:23:45".
millis instant, milliseconds since the Unix epoch (UTC)#formatHttpDate
UTC instant millis as an RFC 7231 HTTP date, e.g."Sun, 10 May 2026 14:23:45 GMT".
millis instant, milliseconds since the Unix epoch (UTC)#yearOf
UTC calendar year of millis.
millis instant, milliseconds since the Unix epoch (UTC)#monthOf
UTC month of millis, 1..12 (1 = January).
millis instant, milliseconds since the Unix epoch (UTC)#dayOf
UTC day of month of millis, 1..31.
millis instant, milliseconds since the Unix epoch (UTC)#hourOf
UTC hour of millis, 0..23.
millis instant, milliseconds since the Unix epoch (UTC)#minuteOf
UTC minute of millis, 0..59.
millis instant, milliseconds since the Unix epoch (UTC)#secondOf
UTC second of millis, 0..59.
millis instant, milliseconds since the Unix epoch (UTC)#millisecondOf
Sub-second millisecond component of millis, 0..999.
millis instant, milliseconds since the Unix epoch (UTC)#dayOfWeek
UTC day of week of millis: 0 = Sunday … 6 = Saturday.
millis instant, milliseconds since the Unix epoch (UTC)#buildEpochMillis
Composes UTC calendar components into milliseconds since the Unix epoch.
An out-of-range component carries into the next unit (month 13 is January
of the following year).
year full calendar year, e.g. 2026month 1..12 (1 = January)day 1..31hour 0..23minute 0..59second 0..59millis sub-second component, 0..999#parseIso8601
Parses "YYYY-MM-DDTHH:MM:SS[.fff][Z]" (a space may stand for the T)
into milliseconds since the Unix epoch (UTC). A fraction keeps its first
three digits; anything after the optional Z is refused. A component
outside its range is not rejected — it carries into the next unit, asbuildEpochMillis documents — so "2026-13-01" names January 2027.
s ISO-8601 timestamp text, e.g. "2026-05-10T14:23:45.123Z"ParseException if s is not a valid ISO-8601 timestamp#__dtFormatIso
#__dtFormatDate
#__dtFormatTime
#__dtPad
Decimal v zero-padded to width characters, the sign counted in the width.
#__dtDayName
#__dtMonthName
#__dtZero
#__dtIsDigit
#__dtDigits
The count ASCII digits of s from start as a number, or -1 on any non-digit.
#__dtParseFailure
#__dtMsPerMinute
#__dtMsPerHour
#__dtMsPerDay
#__dtFloorDiv
a / b rounded toward negative infinity, for a positive b.
#__dtFloorMod
a mod b in 0..b, for a positive b.
#__dtDays
Whole days from the epoch to the UTC day holding millis.
#__dtMillisOfDay
#__dtEra
#__dtDayOfEra
Day of the 400-year era, 0..146096.
#__dtYearOfEra
Year of the era, 0..399.
#__dtDayOfMarchYear
Day of the March-based year, 0..365.
#__dtMarchMonth
Month of the March-based year, 0 = March … 11 = February.
#__dtMonthOfDays
#__dtDayOfDays
#__dtYearOfDays
#__dtDaysFromCivil
C class LocalDateTime
An immutable UTC instant with calendar accessors. The value is its
millis-since-epoch; every plus* returns a fresh LocalDateTime, so a
call chain never alters a receiver someone else still holds.
Constructors
| Type | Method and description |
|---|---|
| constructor(millis : i64) The instant millis since the Unix epoch (UTC). |
Method detail
#constructor
The instant millis since the Unix epoch (UTC).
millis instant, milliseconds since the Unix epoch (UTC)Methods
| Type | Method and description |
|---|---|
| now() : LocalDateTime |
| fromMillis(millis : i64) : LocalDateTime |
| fromComponents( year : i32, month : i32, day : i32, hour : i32, minute : i32, second : i32 ) : LocalDateTime |
| getYear(self) : i32 |
| getMonth(self) : i32 |
| getDay(self) : i32 |
| getHour(self) : i32 |
| getMinute(self) : i32 |
| getSecond(self) : i32 |
| toMillis(self) : i64 |
| plusDays(self, days : i32) : LocalDateTime |
| plusHours(self, hours : i32) : LocalDateTime |
| plusMinutes(self, minutes : i32) : LocalDateTime |
| plusSeconds(self, seconds : i32) : LocalDateTime |
| formatIso(self) : string |
| formatDate(self) : string |