formatTimeOfDay method

  1. @override
String formatTimeOfDay(
  1. TimeOfDay time, {
  2. bool use24HourFormat = true,
  3. bool showSeconds = false,
})
override

Implementation

@override
String formatTimeOfDay(TimeOfDay time,
    {bool use24HourFormat = true, bool showSeconds = false}) {
  String result = '';
  if (use24HourFormat) {
    result +=
        '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
    if (showSeconds) {
      result += ':${time.second.toString().padLeft(2, '0')}';
    }
  } else {
    int hour = time.hour;
    if (hour > 12) {
      hour -= 12;
      if (showSeconds) {
        result +=
            '${hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}:${time.second.toString().padLeft(2, '0')} PM';
      } else {
        result +=
            '${hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')} PM';
      }
    } else {
      if (showSeconds) {
        result +=
            '${hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}:${time.second.toString().padLeft(2, '0')} AM';
      } else {
        result +=
            '${hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')} AM';
      }
    }
  }
  return result;
}