FixedDateTimeFormatter class

A formatter and parser for DateTime in a fixed format String pattern.

For example, calling FixedDateTimeCodec('YYYYMMDDhhmmss').decodeToLocal('19960425050322') has the same result as calling DateTime(1996, 4, 25, 5, 3, 22).

The allowed characters are

  • Y for “calendar year”
  • M for “calendar month”
  • D for “calendar day”
  • E for “decade”
  • C for “century”
  • h for “clock hour”
  • m for “clock minute”
  • s for “clock second”
  • S for “fractional clock second”

Note: Negative years are not supported.

Non-allowed characters in the format pattern are included when decoding a string, in this case YYYY kiwi MM is the same format string as YYYY------MM. When encoding a DateTime, the non-format characters are in the output verbatim.

Note: this class differs from DateFormat from package:intl in that here, the format character count is interpreted literally. For example, using the format string YYY to decode the string 996 would result in the same DateTime as calling DateTime(996), and the same format string used to encode the DateTime(1996) would output only the three digits 996.

Constructors

FixedDateTimeFormatter(String pattern, {bool isUtc = true})
Creates a new FixedDateTimeFormatter with the provided pattern.

Properties

hashCode int
The hash code for this object.
no setterinherited
isUtc bool
Whether to create UTC DateTime objects when parsing.
final
pattern String
The format pattern string of this formatter.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decode(String formattedDateTime) DateTime
Parses formattedDateTime to a DateTime as specified by the pattern.
encode(DateTime dateTime) String
Converts a DateTime to a String as specified by the pattern.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
tryDecode(String formattedDateTime) DateTime?
Parses formattedDateTime to a DateTime as specified by the pattern.
tryParse(String formattedDateTime, int start, int end) int?

Operators

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