getTimeFromDate static method

String getTimeFromDate(
  1. DateTime? date, {
  2. String timeFormat = "hh:mm a'",
})

Extracts and formats the time from a nullable DateTime object.

timeFormat: The desired output format, defaults to "hh:mm a'". Returns an empty string if the date is null or on error.

Implementation

static String getTimeFromDate(
  DateTime? date, {
  String timeFormat = "hh:mm a'",
}) {
  try {
    return DateFormat(timeFormat).format(date!).toUpperCase();
  } catch (e) {
    return '';
  }
}