parseDateTime static method
Tries to parse a DateTime.
- Returns
def
ifvalue
is invalid.
Implementation
static DateTime? parseDateTime(Object? value, [DateTime? def]) {
if (value == null) return def;
if (value is DateTime) {
return value;
} else if (value is int) {
return DateTime.fromMillisecondsSinceEpoch(value);
} else {
var s = '$value'.trim();
var ms = int.tryParse(s);
if (ms != null) {
return DateTime.fromMillisecondsSinceEpoch(ms);
}
return DateTime.tryParse(s) ?? def;
}
}