formatTimeWithAmPm static method
Implementation
static String formatTimeWithAmPm(DateTime time) {
int hour = time.hour;
int minute = time.minute;
String period = hour >= 12 ? 'PM' : 'AM';
// Convert to 12-hour format
hour = hour % 12;
hour = hour == 0 ? 12 : hour; // Handle midnight and noon cases
return "${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')} $period";
}