getDateTime static method

DateTime getDateTime({
  1. String? dateStr,
  2. int? milliseconds,
})

将字符串或者时间戳转化成DateTime

Implementation

static DateTime getDateTime({String? dateStr, int? milliseconds}) {
  DateTime? dateTime;
  if (dateStr != null) {
    dateTime = DateTime.tryParse(dateStr);
    return dateTime!;
  }
  if (milliseconds != null) {
    dateTime = DateTime.fromMillisecondsSinceEpoch(milliseconds);
    return dateTime;
  }
  return dateTime!;
}