format method

String format({
  1. String format = 'dd MMM, yyyy',
  2. String placeholder = '',
})

Formats the DateTime instance to a string based on the provided format.

If the DateTime instance is null, returns the placeholder string.

format specifies the format string as per DateFormat from the intl package. Defaults to 'dd MMM, yyyy'.

placeholder is the string returned when the DateTime instance is null. Defaults to an empty string.

Implementation

String format({String format = 'dd MMM, yyyy', String placeholder = ''}) {
  if (this == null) return placeholder;
  return DateFormat(format).format(this!);
}