utcTimeDisplay method
Fixed-form clock display selected by type (see UtcTimeDisplayEnum).
ASCII spaces in the result are converted to non-breaking (U+00A0) so the
clock never wraps across lines; patterns with no space (e.g. 20:31) are
returned unchanged.
Example:
DateTime(2026, 1, 15, 20, 31)
.utcTimeDisplay(UtcTimeDisplayEnum.twelveHourAMPM); // '8:31 PM'
Audited: 2026-06-12 11:26 EDT
Implementation
String utcTimeDisplay(UtcTimeDisplayEnum type, {String? locale}) {
final String formatted = switch (type) {
UtcTimeDisplayEnum.twelveHourWithSecondsAMPM => DateFormat.jms(locale).format(this),
UtcTimeDisplayEnum.twelveHourAMPM => DateFormat.jm(locale).format(this),
UtcTimeDisplayEnum.twentyFourHourWithSeconds => DateFormat.Hms(locale).format(this),
UtcTimeDisplayEnum.twentyFourHour => DateFormat.Hm(locale).format(this),
UtcTimeDisplayEnum.twelveHour => DateFormat('h:mm', locale).format(this),
UtcTimeDisplayEnum.amPmOnly => DateFormat('a', locale).format(this),
};
return formatted.replaceAll(' ', ' ');
}