dateToString static method

String dateToString(
  1. DateTime? date, {
  2. required String format,
})

Converts a DateTime into a formatted string using the given format.

Returns an empty string if date is null.

Example:

DateTimeUtils.dateToString(DateTime.now(), format: "yyyy-MM-dd");

Implementation

static String dateToString(DateTime? date, {required String format}) {
  if (date == null) {
    return '';
  }
  return DateFormat(format).format(date);
}