formatTime static method

String formatTime(
  1. TimeOfDay? time, {
  2. bool use24hFormat = true,
})

Formats a time (24h by default) via the helper-kit extension.

Implementation

static String formatTime(TimeOfDay? time, {bool use24hFormat = true}) {
  if (time == null) return '';
  final DateTime now = DateTime.now();
  final DateTime dt = DateTime(
    now.year,
    now.month,
    now.day,
    time.hour,
    time.minute,
  );
  return dt.format(pattern: use24hFormat ? 'HH:mm' : 'hh:mm a');
}