date static method

DateTime? date(
  1. dynamic value, {
  2. bool inSec = false,
})

Tries to parse value int DateTime

num - milliseconds or seconds - isSec true String - ISO formatted date and time. Timestamp or any other object with toDate method.

Implementation

static DateTime? date(dynamic value, {bool inSec = false}) {
  if (value is num) {
    return DateTime.fromMillisecondsSinceEpoch(
        inSec ? value * 1000 as int : value as int);
  }

  if (value is String) {
    return DateTime.tryParse(value);
  }

  try {
    return value.toDate();
  } on NoSuchMethodError {
    return null;
  }
}