MoonBit date-time formatting: epoch-milliseconds to ISO 8601 and RFC 5322 timestamps, UTC only
moon add chensuiyi/dateku| Function | Description |
|---|---|
| now_ms() | Current epoch milliseconds |
| now_unix() | Current epoch seconds |
| iso8601(epoch_ms) | 2026-10-03T08:15:30.123Z |
| rfc5322(epoch_ms) | Sat, 03 Oct 2026 08:15:30 +0000 |
| year(epoch_ms) | UTC year |
| month(epoch_ms) | UTC month, 1-12 |
| day(epoch_ms) | UTC day of month, 1-31 |
| hour(epoch_ms) | UTC hour, 0-23 |
| minute(epoch_ms) | UTC minute, 0-59 |
| second(epoch_ms) | UTC second, 0-59 |
| millisecond(epoch_ms) | UTC millisecond, 0-999 |
| make_epoch(y, m, d, ...) | Construct epoch ms; parts roll over |
| is_leap_year(y) | Gregorian leap year |
| days_in_month(y, m) | 28-31, 0 for invalid month |
| add_days / add_hours / add_minutes / add_seconds(e, n) | Shift, negative = backwards |
| start_of_day(e) | UTC midnight of that day |
| is_same_day(a, b) | Same UTC day |
@dateku.iso8601(1791015330123UL) // "2026-10-03T08:15:30.123Z"
@dateku.rfc5322(1791015330000UL) // "Sat, 03 Oct 2026 08:15:30 +0000"
// Components
let e = @dateku.make_epoch(2026, 10, 3, hour=8, minute=15, second=30)
@dateku.year(e) // 2026
@dateku.hour(e) // 8
// Shifts and day queries
let tomorrow = @dateku.add_days(e, 1)
@dateku.is_same_day(e, tomorrow) // false
@dateku.start_of_day(e) == @dateku.make_epoch(2026, 10, 3) // true
// Calendar
@dateku.is_leap_year(2024) // true
@dateku.days_in_month(2026, 2) // 28moon add chensuiyi/dateku| 函数 | 说明 |
|---|---|
| now_ms() | 当前 epoch 毫秒 |
| now_unix() | 当前 epoch 秒 |
| iso8601(epoch_ms) | 2026-10-03T08:15:30.123Z |
| rfc5322(epoch_ms) | Sat, 03 Oct 2026 08:15:30 +0000 |
| year(epoch_ms) | UTC 年 |
| month(epoch_ms) | UTC 月,1-12 |
| day(epoch_ms) | UTC 日,1-31 |
| hour(epoch_ms) | UTC 时,0-23 |
| minute(epoch_ms) | UTC 分,0-59 |
| second(epoch_ms) | UTC 秒,0-59 |
| millisecond(epoch_ms) | UTC 毫秒,0-999 |
| make_epoch(y, m, d, ...) | 构造 epoch 毫秒,分量越界进位 |
| is_leap_year(y) | 格里高利闰年 |
| days_in_month(y, m) | 28-31,月份非法返回 0 |
| add_days / add_hours / add_minutes / add_seconds(e, n) | 平移,负数回退 |
| start_of_day(e) | 当日 UTC 零点 |
| is_same_day(a, b) | 同一 UTC 日 |
@dateku.iso8601(1791015330123UL) // "2026-10-03T08:15:30.123Z"
@dateku.rfc5322(1791015330000UL) // "Sat, 03 Oct 2026 08:15:30 +0000"
// 分量读取
let e = @dateku.make_epoch(2026, 10, 3, hour=8, minute=15, second=30)
@dateku.year(e) // 2026
@dateku.hour(e) // 8
// 平移与日查询
let tomorrow = @dateku.add_days(e, 1)
@dateku.is_same_day(e, tomorrow) // false
@dateku.start_of_day(e) == @dateku.make_epoch(2026, 10, 3) // true
// 日历
@dateku.is_leap_year(2024) // true
@dateku.days_in_month(2026, 2) // 28fn add_days(epoch_ms : UInt64, days : Int) -> UInt64fn add_hours(epoch_ms : UInt64, hours : Int) -> UInt64fn add_minutes(epoch_ms : UInt64, minutes : Int) -> UInt64fn add_seconds(epoch_ms : UInt64, seconds : Int) -> UInt64fn days_in_month(year : Int, month : Int) -> Intfn is_same_day(a : UInt64, b : UInt64) -> Boolfn iso8601(epoch_ms : UInt64) -> Stringfn make_epoch(year : Int, month : Int, day : Int, hour? : Int, minute? : Int, second? : Int, millisecond? : Int) -> UInt64fn rfc5322(epoch_ms : UInt64) -> Stringfn start_of_day(epoch_ms : UInt64) -> UInt64Install
Download zipMoonBit date-time formatting: epoch-milliseconds to ISO 8601 and RFC 5322 timestamps, UTC only