Skip to content

DateTime Class

The DateTime class provides timestamp operations, formatting, and arithmetic.

dt = new DateTime

dt.now()

Get the current local datetime string in ISO format.

cNow = dt.now()  # "2026-05-02T14:30:00"

dt.nowUtc()

Get the current UTC datetime string in ISO format.

cUtc = dt.nowUtc()

dt.timestamp()

Get the current Unix timestamp in seconds.

ts = dt.timestamp()

dt.timestampMs()

Get the current Unix timestamp in milliseconds.

tsMs = dt.timestampMs()

dt.formatDate(nTimestamp, cFormat)

Format a Unix timestamp to a string.

cDate = dt.formatDate(ts, "%Y-%m-%d %H:%M:%S")  # "2026-05-02 14:30:00"

dt.parseDate(cDateStr, cFormat)

Parse a datetime string to a Unix timestamp.

ts = dt.parseDate("2026-05-02 14:30:00", "%Y-%m-%d %H:%M:%S")

dt.diff(nTs1, nTs2)

Calculate the difference between two timestamps in seconds.

diff = dt.diff(ts1, ts2)

dt.addDays(nTimestamp, nDays)

Add days to a timestamp.

future = dt.addDays(ts, 7)  # 7 days from now

dt.addHours(nTimestamp, nHours)

Add hours to a timestamp.

future = dt.addHours(ts, 24)  # 24 hours from now