isDateTime method
Checks if the String value is convertible to DateTime.
Returns true
if the string can be parsed as a valid DateTime.
Otherwise, returns false
.
Example:
String? dateStr = "2023-04-28T05:34:53.684Z";
print(dateStr.isDateTime()); // true
String? invalidDateStr = "not_a_date";
print(invalidDateStr.isDateTime()); // false
Implementation
bool isDateTime() =>
isNotEmptyOrNull ? DateTime.tryParse(this!) != null : false;