timeOfDay property

String timeOfDay

Time Of Day

Returns time of day in the format Morning, Afternoon, Evening or Night

Usage:

DateTime.now().timeOfDay

Result:

Morning

Implementation

String get timeOfDay {
  if (hour >= 0 && hour < 12) {
    return 'Morning';
  } else if (hour >= 12 && hour < 16) {
    return 'Afternoon';
  } else if (hour >= 16 && hour < 20) {
    return 'Evening';
  } else {
    return 'Night';
  }
}