asDateTimeOrThrow method

DateTime asDateTimeOrThrow({
  1. PickDateFormat? format,
})

Parses the picked value as ISO 8601 String to DateTime or throws

Shorthand for .required().asDateTime()

Tries to parse the most common date formats such as ISO 8601, RFC 3339, RFC 1123, RFC 5322 and ANSI C's asctime()

Optionally accepts a format defining the exact to be parsed format. By default, all formats will be attempted

Examples of parsable date formats:

  • '2012-02-27 13:27:00'
  • '2012-02-27 13:27:00.123456z'
  • '2012-02-27 13:27:00,123456z'
  • '20120227 13:27:00'
  • '20120227T132700'
  • '20120227'
  • '+20120227'
  • '2012-02-27T14Z'
  • '2012-02-27T14+00:00'
  • '-123450101 00:00:00 Z': in the year -12345.
  • '2002-02-27T14:00:00-0500': Same as '2002-02-27T19:00:00Z'
  • 'Thu, 1 Jan 1970 00:00:00 GMT'
  • 'Thursday, 1-Jan-1970 00:00:00 GMT'
  • 'Thu Jan 1 00:00:00 1970'

Implementation

DateTime asDateTimeOrThrow({PickDateFormat? format}) {
  withContext(
    requiredPickErrorHintKey,
    'Use asDateTimeOrNull() when the value may be null/absent at some point (DateTime?).',
  );
  return _parse(format: format);
}