toDate property

DateTime? toDate

Attempts to parse the string into a DateTime object. Returns null if the parsing fails.

Example:

print('2023-01-01'.toDate); // Output: Instance of 'DateTime' for 2023-01-01
print('abc'.toDate); // Output: null

Implementation

DateTime? get toDate => isNumeric ? toInt?.toDateTime : DateTime.tryParse(this);