formatDateTime method

  1. @override
String formatDateTime(
  1. DateTime dateTime, {
  2. bool showDate = true,
  3. bool showTime = true,
  4. bool showSeconds = false,
  5. 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;
}