to12HourTime method

String to12HourTime()

Format DateTime as 12-Hour Time with AM/PM: hh:MM:SS AM/PM

Implementation

String to12HourTime() {
  String period = this.hour < 12 ? 'AM' : 'PM';
  int hour = this.hour % 12 == 0 ? 12 : this.hour % 12;
  return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')} $period';
}