DateTime
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'
(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'
"Get current date and time"
| now <DateTime> |
now := DateTime now.
now year printString
"Parse an ISO date string"
| dt <DateTime> |
dt := DateTime parse: '2025-03-14' format: '2006-01-02'.
dt year "=> 2025"
"Date arithmetic"
| dt <DateTime> later <DateTime> |
dt := DateTime fromEpoch: 0.
later := dt addDays: 365.
later year "=> 1971"
Class Methods
primitives
Instance Methods
primitives
Return a new DateTime offset by the given number of days.
Return a new DateTime offset by the given number of hours.
Return a new DateTime offset by the given number of minutes.
Return a new DateTime offset by the given number of seconds.
Return the day of month (1-31).
Return the difference in seconds between self and another DateTime (self - other). Positive if self is later.
Return the Unix epoch timestamp in milliseconds.
Return the Unix epoch timestamp in seconds.
Format the receiver using a Go layout string.
Return the hour (0-23).
Return the minute (0-59).
Return the month (1-12).
Return an ISO 8601 (RFC3339) string representation.
Return the second (0-59).
Return the year component.