formatDateTime method
String
formatDateTime(
- DateTime dateTime, {
- bool showDate = true,
- bool showTime = true,
- bool showSeconds = false,
- bool use24HourFormat = true,
override
Implementation
@override
String formatDateTime(DateTime dateTime,
{bool showDate = true,
bool showTime = true,
bool showSeconds = false,
bool use24HourFormat = true}) {
String result = '';
if (showDate) {
result += '${getMonth(dateTime.month)} ${dateTime.day}, ${dateTime.year}';
}
if (showTime) {
if (use24HourFormat) {
if (result.isNotEmpty) {
result += ' ';
}
result += '${dateTime.hour}:${dateTime.minute}';
if (showSeconds) {
result += ':${dateTime.second}';
}
} else {
if (result.isNotEmpty) {
result += ' ';
}
int hour = dateTime.hour;
if (hour > 12) {
hour -= 12;
result += '$hour:${dateTime.minute} PM';
} else {
result += '$hour:${dateTime.minute} AM';
}
}
}
return result;
}