p-datetime
The datetime module provides date/time creation, extraction, formatting, and arithmetic functions. All timestamps are millisecond-precision Unix epoch values.
use p-datetime as dtCurrent Time
Section titled “Current Time”Returns the current timestamp in milliseconds.
today[]
Section titled “today[]”Returns the timestamp for the start of today (midnight, local time).
timestamp[]
Section titled “timestamp[]”Returns the current Unix timestamp in seconds (integer).
use p-datetime as dtconst t be dt.now[] -- e.g. 1712534400000const s be dt.timestamp[] -- e.g. 1712534400Create
Section titled “Create”create[year; month; day; hour; minute; second; ms]
Section titled “create[year; month; day; hour; minute; second; ms]”Creates a timestamp from local date/time components. Only year is required; others default to sensible values (month=1, day=1, hour/minute/second/ms=0).
use p-datetime as dtconst t be dt.create[2026; 4; 8]const t2 be dt.create[2026; 4; 8; 14; 30; 0; 0]utccreate[year; month; day; hour; minute; second; ms]
Section titled “utccreate[year; month; day; hour; minute; second; ms]”Same as create but interprets components as UTC.
use p-datetime as dtconst t be dt.utccreate[2026; 4; 8; 0; 0; 0; 0]fromiso[str]
Section titled “fromiso[str]”Parses an ISO 8601 date string and returns a timestamp.
use p-datetime as dtconst t be dt.fromiso[///2026-04-08T00:00:00Z///]Extract Components (Local)
Section titled “Extract Components (Local)”These functions extract date/time components in the local timezone.
year[t]
Section titled “year[t]”Returns the full year (e.g. 2026).
month[t]
Section titled “month[t]”Returns the month (1–12).
day[t]
Section titled “day[t]”Returns the day of the month (1–31).
weekday[t]
Section titled “weekday[t]”Returns the day of the week (0=Sunday, 6=Saturday).
hour[t] / minute[t] / second[t] / ms[t]
Section titled “hour[t] / minute[t] / second[t] / ms[t]”Returns the respective time component.
use p-datetime as dtconst t be dt.now[]console.log[dt.year[t]] -- e.g. 2026console.log[dt.month[t]] -- e.g. 4console.log[dt.weekday[t]] -- e.g. 3 (Wednesday)Extract Components (UTC)
Section titled “Extract Components (UTC)”Same as local extraction but in UTC.
utcyear[t] / utcmonth[t] / utcday[t] / utcweekday[t]
Section titled “utcyear[t] / utcmonth[t] / utcday[t] / utcweekday[t]”utchour[t] / utcminute[t] / utcsecond[t] / utcms[t]
Section titled “utchour[t] / utcminute[t] / utcsecond[t] / utcms[t]”use p-datetime as dtconst t be dt.now[]console.log[dt.utchour[t]] -- UTC hourExtract Components (Timezone)
Section titled “Extract Components (Timezone)”Extract components for a specific IANA timezone.
tzyear[t; tz] / tzmonth[t; tz] / tzday[t; tz] / tzweekday[t; tz]
Section titled “tzyear[t; tz] / tzmonth[t; tz] / tzday[t; tz] / tzweekday[t; tz]”tzhour[t; tz] / tzminute[t; tz] / tzsecond[t; tz]
Section titled “tzhour[t; tz] / tzminute[t; tz] / tzsecond[t; tz]”use p-datetime as dtconst t be dt.now[]console.log[dt.tzhour[t; ///America/New_York///]]console.log[dt.tzhour[t; ///Asia/Tokyo///]]Format
Section titled “Format”toiso[t]
Section titled “toiso[t]”Returns the ISO 8601 string representation.
use p-datetime as dtdt.toiso[dt.now[]] -- e.g. "2026-04-08T05:00:00.000Z"tolocale[t; locale; options]
Section titled “tolocale[t; locale; options]”Returns a locale-formatted date/time string.
todate[t; locale; options]
Section titled “todate[t; locale; options]”Returns a locale-formatted date string (date only).
totime[t; locale; options]
Section titled “totime[t; locale; options]”Returns a locale-formatted time string (time only).
format[t; tz; locale; options]
Section titled “format[t; tz; locale; options]”Returns a formatted string for a specific timezone and locale.
use p-datetime as dtconst t be dt.now[]dt.tolocale[t; ///en-US///]dt.todate[t; ///ja-JP///]dt.format[t; ///Asia/Tokyo///; ///ja-JP///]Arithmetic
Section titled “Arithmetic”addms[t; n]
Section titled “addms[t; n]”Adds n milliseconds.
addseconds[t; n]
Section titled “addseconds[t; n]”Adds n seconds.
addminutes[t; n]
Section titled “addminutes[t; n]”Adds n minutes.
addhours[t; n]
Section titled “addhours[t; n]”Adds n hours.
adddays[t; n]
Section titled “adddays[t; n]”Adds n days.
use p-datetime as dtconst t be dt.now[]const tomorrow be dt.adddays[t; 1]const later be dt.addhours[t; 3]Comparison
Section titled “Comparison”diff[a; b]
Section titled “diff[a; b]”Returns the difference in milliseconds (a - b).
diffdays[a; b]
Section titled “diffdays[a; b]”Returns the difference in days.
diffhours[a; b]
Section titled “diffhours[a; b]”Returns the difference in hours.
diffminutes[a; b]
Section titled “diffminutes[a; b]”Returns the difference in minutes.
diffseconds[a; b]
Section titled “diffseconds[a; b]”Returns the difference in seconds.
use p-datetime as dtconst a be dt.create[2026; 4; 10]const b be dt.create[2026; 4; 8]console.log[dt.diffdays[a; b]] -- 2Timezone Info
Section titled “Timezone Info”offset[t]
Section titled “offset[t]”Returns the timezone offset in minutes for the given timestamp (or now if omitted).
localtz[]
Section titled “localtz[]”Returns the local IANA timezone name (e.g. "Asia/Tokyo").
use p-datetime as dtconsole.log[dt.localtz[]] -- e.g. "Asia/Tokyo"console.log[dt.offset[]] -- e.g. -540