← index

DateTime

inherits Object

A zone-aware date and time: an instant plus its time zone, so calendar components, DST, and offsets all come out right.

Read components with year / month / day / hour / … / weekday; shift by absolute time with +: / -: (Duration) or by calendar units with plusDays: / plusMonths: / … (DST- and end-of-month-aware); re-view the same instant elsewhere with inZone:. Prints and parses as RFC 9557 — RFC 3339 plus a [Zone] suffix. Comparison (<:, ==:) is by instant, regardless of zone.

var noon = DateTime.parse:'2024-01-01T12:00:00-05:00[America/New_York]'
noon.weekday                        "* -> 'Monday'
(noon.plusMonths:1).s               "* -> 2024-02-01T12:00:00-05:00[America/New_York]
(noon.inZone:(TimeZone.of:'Asia/Tokyo')).s
"* -> 2024-01-02T02:00:00+09:00[Asia/Tokyo]
extended at core/16-serialize.qn:18

The zone-aware instant, as its RFC 9557 string ('…+09:00[Asia/Tokyo]') — lossless for Quoin (DateTime.parse: reads it back, zone and all). For bare RFC 3339 interop, serialize .timestamp instead.

Class methods

now

The current date and time in the host's local time zone.

native

nowIn:TimeZone

The current date and time in the given zone: DateTime.nowIn:(TimeZone.of:'Asia/Tokyo').

native

nowUtc

The current date and time in UTC.

native

parse:String

Parse an RFC 9557 zoned datetime string — RFC 3339 plus a [Zone] suffix (throws a ValueError on anything else). The inverse of s.

(DateTime.parse:'2024-01-01T12:00:00-05:00[America/New_York]').year     "* -> 2024

native

Instance methods

+:Duration
+:Span

The DateTime shifted later by a Duration — absolute time, so adding 24 hours across a DST change moves the wall clock. For calendar arithmetic use plusDays: and friends. Leaving the representable range throws an ArithmeticError.

((DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]') + (Duration.minutes:90)).s
"* -> 2024-01-01T13:30:00+00:00[UTC]

native

-:Duration
-:DateTime
-:Span

With a Duration argument: the DateTime shifted earlier by that much (absolute time; the calendar-aware counterpart is minusDays: and friends).

((DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]') - (Duration.minutes:90)).s
"* -> 2024-01-01T10:30:00+00:00[UTC]

native

<:DateTime

Whether the receiver names the earlier instant — compared by instant, so zones don't matter. Only <: is native; >: / <=: / >=: derive from it on Object.

native

==:

Whether the argument is a DateTime naming the same instant — the zone is not compared, so noon UTC equals 7am New York. A non-DateTime argument is simply unequal.

(DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]') == (DateTime.parse:'2024-01-01T07:00:00-05:00[America/New_York]')
"* -> true

native

asData

core/16-serialize.qn:19

date

The civil calendar Date of this DateTime's local components (the zone-dependent view: the same instant is a different date in Tokyo and Honolulu).

(DateTime.parse:'2026-07-11T09:40:00+00:00[UTC]').date.s     "* -> 2026-07-11

native

day

The day of the month, 1–31 (Integer).

native

hour

The hour of the day, 0–23 (Integer).

native

inZone:TimeZone

The same instant viewed in another zone — only the local components change.

((DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]').inZone:(TimeZone.of:'Asia/Tokyo')).s
"* -> 2024-01-01T21:00:00+09:00[Asia/Tokyo]

native

minusDays:Integer

The DateTime n calendar days earlier — plusDays: in reverse.

((DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]').minusDays:1).s
"* -> 2023-12-31T12:00:00+00:00[UTC]

native

minusMonths:Integer

The DateTime n calendar months earlier, clamping to the end of a shorter month (like plusMonths:).

native

minusWeeks:Integer

The DateTime n calendar weeks earlier.

native

minusYears:Integer

The DateTime n calendar years earlier.

native

minute

The minute of the hour, 0–59 (Integer).

native

month

The month of the year, 1–12 (Integer).

native

nanosecond

The subsecond part in nanoseconds, 0–999999999 (Integer).

native

plusDays:Integer

The DateTime n calendar days later. Calendar arithmetic keeps the wall-clock time, so a day across a DST change is not 24 absolute hours.

((DateTime.parse:'2024-11-03T00:00:00-04:00[America/New_York]').plusDays:1).s
"* -> 2024-11-04T00:00:00-05:00[America/New_York]

native

plusMonths:Integer

The DateTime n calendar months later, clamping to the end of a shorter month.

((DateTime.parse:'2024-01-31T12:00:00+00:00[UTC]').plusMonths:1).s
"* -> 2024-02-29T12:00:00+00:00[UTC]

native

plusWeeks:Integer

The DateTime n calendar weeks later (DST-aware, like plusDays:).

native

plusYears:Integer

The DateTime n calendar years later (Feb 29 clamps to Feb 28 in a non-leap year).

native

s

The RFC 9557 string: RFC 3339 plus an [IANA/Zone] suffix. Round-trips through DateTime.parse:.

(DateTime.parse:'2024-01-01T12:00:00-05:00[America/New_York]').s
"* -> 2024-01-01T12:00:00-05:00[America/New_York]

native

second

The second of the minute, 0–59 (Integer).

native

time

The wall-clock Time of this DateTime's local components.

(DateTime.parse:'2026-07-11T09:40:00+00:00[UTC]').time.s     "* -> 09:40:00

native

timeZone

The TimeZone this DateTime is expressed in.

native

timestamp

The underlying absolute instant, as a zone-less Timestamp.

(DateTime.parse:'2024-01-01T12:00:00-05:00[America/New_York]').timestamp.s
"* -> 2024-01-01T17:00:00Z

native

until:DateTime

The calendar Span from the receiver to the argument (negative when the argument is earlier), in years/months/days/hours/… — zone-aware, so a day across a DST change counts as one day. The absolute-time diff is -: (→ Duration).

((DateTime.parse:'2024-01-15T00:00:00+00:00[UTC]').until:(DateTime.parse:'2026-03-18T00:00:00+00:00[UTC]')).s
"* -> 2y 2mo 3d

native

weekday

The English weekday name.

(DateTime.parse:'2024-01-01T12:00:00+00:00[UTC]').weekday     "* -> 'Monday'

native

year

The calendar year (Integer), in this DateTime's own zone.

native