DateTime

Inherits from: Object

Date and time values wrapping Go's time.Time. DateTime instances are immutable — arithmetic methods return new DateTime objects.

Uses Go-style layout strings for parsing and formatting. The reference time is Mon Jan 2 15:04:05 MST 2006 (Go's reference layout).

Common layouts: - '2006-01-02' — date only - '15:04:05' — time only - '2006-01-02 15:04:05' — date and time - RFC3339: '2006-01-02T15:04:05Z07:00'

Test
(DateTime fromEpoch: 0) epochSeconds >>> 0
(DateTime fromEpoch: 1000) year >>> 1970
(DateTime fromEpoch: 0) format: '2006' >>> '1970'
(DateTime parse: '2025-06-15' format: '2006-01-02') month >>> 6
(DateTime parse: '2025-06-15' format: '2006-01-02') day >>> 15
(DateTime parse: '2025-06-15 14:30:00' format: '2006-01-02 15:04:05') hour >>> 14
(DateTime parse: '2025-06-15 14:30:00' format: '2006-01-02 15:04:05') minute >>> 30
(DateTime parse: '2025-06-15 14:30:45' format: '2006-01-02 15:04:05') second >>> 45
(DateTime parse: '2025-03-14' format: '2006-01-02') format: '01/02/2006' >>> '03/14/2025'
(DateTime fromEpoch: 0) epochMillis >>> 0
(DateTime fromEpoch: 3600) epochSeconds >>> 3600
((DateTime fromEpoch: 0) addSeconds: 60) epochSeconds >>> 60
((DateTime fromEpoch: 0) addMinutes: 5) epochSeconds >>> 300
((DateTime fromEpoch: 0) addHours: 2) epochSeconds >>> 7200
((DateTime fromEpoch: 0) addDays: 1) epochSeconds >>> 86400
(DateTime fromEpoch: 100) differenceFrom: (DateTime fromEpoch: 0) >>> 100
(DateTime fromEpoch: 0) differenceFrom: (DateTime fromEpoch: 100) >>> -100
(DateTime fromEpoch: 0) printString >>> '1970-01-01T00:00:00Z'
Example
"Get current date and time"
| now <DateTime> |
now := DateTime now.
now year printString
Example
"Parse an ISO date string"
| dt <DateTime> |
dt := DateTime parse: '2025-03-14' format: '2006-01-02'.
dt year   "=> 2025"
Example
"Date arithmetic"
| dt <DateTime> later <DateTime> |
dt := DateTime fromEpoch: 0.
later := dt addDays: 365.
later year  "=> 1971"

Class Methods

primitives

class fromEpoch:
class now
class parse:format:

Instance Methods

primitives

addDays:

Return a new DateTime offset by the given number of days.

addHours:

Return a new DateTime offset by the given number of hours.

addMinutes:

Return a new DateTime offset by the given number of minutes.

addSeconds:

Return a new DateTime offset by the given number of seconds.

day

Return the day of month (1-31).

differenceFrom:

Return the difference in seconds between self and another DateTime (self - other). Positive if self is later.

epochMillis

Return the Unix epoch timestamp in milliseconds.

epochSeconds

Return the Unix epoch timestamp in seconds.

format:

Format the receiver using a Go layout string.

hour

Return the hour (0-23).

minute

Return the minute (0-59).

month

Return the month (1-12).

printString

Return an ISO 8601 (RFC3339) string representation.

second

Return the second (0-59).

year

Return the year component.