makeDisplayTime method
Display time like 3:30 PM / 15:30 (locale clock), or hour-only when
minutes are zero.
Defaults to the locale's clock convention (12h AM/PM vs 24h), detected from
intl's jm skeleton (an 'H' in the pattern means 24h); override with
hour24 / showAMPM. omitZeroMinutes drops the :00 on whole hours.
The clock and its AM/PM marker are joined with a non-breaking space
(U+00A0) so a bare time never wraps across two lines; any , N s seconds
suffix stays breakable. Returns null on failure.
Audited: 2026-06-12 11:26 EDT
Implementation
String? makeDisplayTime({
bool showSeconds = false,
bool? showAMPM,
bool? hour24,
bool omitZeroMinutes = true,
String? locale,
}) {
// A capital-H hour token in the jm skeleton means the locale uses a 24h
// clock; its absence means a 12h clock with an AM/PM marker.
try {
final bool localeUses24Hour = DateFormat.jm(locale).pattern?.contains('H') ?? false;
final bool is24 = hour24 ?? localeUses24Hour;
final _ClockSpec spec = _ClockSpec(
is24Hour: is24,
// AM/PM is meaningless on a 24h clock; suppress it whenever 24h is in effect.
hasAMPM: (showAMPM ?? !localeUses24Hour) && !is24,
shouldOmitZeroMinutes: omitZeroMinutes,
hasSeconds: showSeconds,
);
return _composeDisplayTime(this, spec, locale);
// Unloaded/malformed locale must degrade to null, never crash a UI.
// ignore: require_catch_logging -- display contract: never throw, callers fall back on null
} on Object {
return null;
}
}