tryFormat static method

String tryFormat(
  1. DateTime? date,
  2. DateFormat format
)

Returns an empty string if DateFormat.format() throws or date is null.

Implementation

static String tryFormat(DateTime? date, DateFormat format) {
  if (date != null) {
    try {
      return format.format(date);
    } catch (e) {
      // print('Error formatting date: $e');
    }
  }
  return '';
}