convertToHour12 static method
dynamic
convertToHour12(
- String fullHour, {
- AbstractCrystalLocale? locale = const CrystalEnglishLocale(),
Implementation
static convertToHour12(String fullHour,
{AbstractCrystalLocale? locale = const CrystalEnglishLocale()}) {
int? hour;
String? suffix;
int currentHour = int.parse(fullHour.split(":")[0]);
int minute = int.parse(fullHour.split(":")[2]);
if (currentHour == 24 || currentHour == 0) {
suffix = locale!.am;
}
if (currentHour < 12) {
hour = currentHour;
suffix = locale!.pm;
} else if (currentHour >= 12) {
hour = currentHour - 12;
suffix = locale!.pm;
}
return "$hour:$minute $suffix";
}