formatDateTime method

String formatDateTime(
  1. DateTime date,
  2. bool diffToNow, {
  3. String? format,
})

Method to build a String representing a DateTime

Implementation

String formatDateTime(DateTime date, bool diffToNow, {String? format}) {
  if (!diffToNow) {
    format ??= Strings.get("_date_time_format_", fallbackValue: null);
  }
  if (format != null) {
    return DateFormat(format).format(date.toLocal());
  }

  if (formatDate(date.toLocal(), true) == formatDate(DateTime.now(), true)) {
    return formatTime(date.toLocal(), true);
  } else {
    return formatDate(date.toLocal(), true);
  }
}