getTime static method

String? getTime({
  1. DateTime? dateTime,
  2. int? milliseconds,
  3. DateFormat format = DateFormat.NORMAL,
  4. String? dateSeparate,
  5. String? timeSeparate,
  6. bool? isZh = false,
})

DateTime或者时间戳转字符串

Implementation

static String? getTime({
  DateTime? dateTime,
  int? milliseconds,
  DateFormat format = DateFormat.NORMAL,
  String? dateSeparate,
  String? timeSeparate,
  bool? isZh = false,
}) {
  String? result;
  if (dateTime == null && milliseconds == null) {
    String dateStr = DateTime.now().toString();
    result = formatDateTime(dateStr, format, dateSeparate, timeSeparate, isZh);
  }
  if (dateTime != null) {
    String dateStr = dateTime.toString();
    result = formatDateTime(dateStr, format, dateSeparate, timeSeparate, isZh);
    return result;
  }
  if (milliseconds != null) {
    if (milliseconds == 0) {
      result = "";
    }
    DateTime dateTime = getDateTime(milliseconds: milliseconds);
    result = getTime(
      dateTime: dateTime,
      format: format,
      dateSeparate: dateSeparate,
      timeSeparate: timeSeparate,
    );
  }
  return result;
}