tryParseStrict method

DateTime? tryParseStrict(
  1. String inputString, [
  2. bool utc = false
])

Given user input, attempt to parse the inputString into the anticipated format, treating it as being in the local timezone.

If inputString does not match our format, returns null. This will reject dates whose values are not strictly valid, even if the DateTime constructor will accept them. It will also reject strings with additional characters (including whitespace) after a valid date. For looser parsing, use tryParse.

Implementation

DateTime? tryParseStrict(String inputString, [bool utc = false]) {
  try {
    return parseStrict(inputString, utc);
  } on FormatException {
    return null;
  }
}