toDateFormatted method

DateTime toDateFormatted(
  1. String format,
  2. String? locale, {
  3. bool utc = false,
})

Parses this string using the supplied format and locale.

The format string should follow the DateFormat patterns (e.g., "MM/dd/yyyy"). If utc is true, the result will be in UTC.

Implementation

DateTime toDateFormatted(String format, String? locale, {bool utc = false}) {
  final df = _createDateFormat(format, locale);
  final input = trim();
  final dt = utc ? df.parseUtc(input) : df.parse(input);
  return utc ? dt.toUtc() : dt;
}