DateTimeParser class

Parses a calendar date or a date-time into a DateTime.

Throws FormatException if value is not a valid date or date-time.

A calendar date is YYYY-MM-DD or the compact form YYYYMMDD (four-digit year, optional + or - sign). A date-time adds a time, separated by T, a space, or one of -_/:t. The time is HH[:MM[:SS[(.|,)fraction]]], then an optional Z or numeric offset (±HH, ±HHMM, or ±HH:MM).

Components must be in range. 2026-02-31 does not roll into March, and hour 24, minute 60, and second 60 are rejected. Fractional seconds longer than 6 digits are rejected instead of being truncated.

The zone follows DateTime.parse: a value with no offset is local, and Z or a numeric offset is UTC. A numeric offset is converted to UTC.

When dateOnly is true, a time part is rejected. The result is local midnight on that calendar date. A local midnight that falls on a different calendar day, which can happen when a time zone skips that day, is rejected.

Inheritance

Constructors

DateTimeParser({bool dateOnly = false})
const

Properties

dateOnly → bool
When true, only a calendar date is accepted.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

format(DateTime value) → String
Formats value as text that parse accepts.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parse(String value) → DateTime
Converts a source string value to the specific option value type. Must throw a FormatException with an appropriate message if the value cannot be parsed.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited