A booking app shows a German user "2:30 PM" for their dentist appointment, while a user in Chicago sees "14:30" on the same screen in another build. Both are correct times. Both look wrong to the person reading them. Then a third user, who switched their iPhone to 24-hour time, reports that the app can no longer read times back from its own form.
Getting the 12-hour vs 24-hour time format right is a small rendering decision that touches every schedule, chat timestamp, alarm, and time picker. This guide is for web and mobile engineers who own those screens. It explains who actually decides the clock format (the locale, the user, or your app), why hour12: false and hand-typed patterns break, and how to build time labels on the web, iOS, and Android that follow the right preference and survive midnight.
The short answer
- Never type
h,H,a, orHHinto a pattern that users will read. Ask the platform for a time pattern instead. - Let the locale's default apply first, then honor the user's own 12-hour or 24-hour override where the platform exposes it.
- On the web, where the operating system setting is invisible, offer an explicit in-app clock setting.
- When you force a cycle, ask for
h23orh12by name. Do not usehour12: false, and never puth24orh11in UI. - Keep wire formats on a fixed, locale-neutral formatter, separate from display.
Who decides the clock format
Three different parties have a claim on how an hour is written, and most bugs come from listening to only one of them.
The locale. Unicode CLDR publishes preferred and allowed hour formats per region in its time data. The UTS 35 dates specification shows the shape of that data: most of the world defaults to H (0 to 23), the United States and many other regions default to h (1 to 12 with a day period), and some locales such as Tamil in India prefer hB, a 12-hour clock with a flexible day period like "in the morning". Language alone does not settle it. English in the US and English in the UK default to different clocks.
The user. Phones let people override the regional default. Apple's Technical Q&A QA1480 describes the iOS switch under Settings > General > Date & Time > 24-Hour Time. Android exposes the same choice, and its DateFormat.is24HourFormat(Context) returns whether times should be formatted as 24-hour times for that context, based on the locale and the user's preference. A traveler from Germany using a US-region phone, or a US engineer who prefers 24-hour time, will set this and expect apps to follow.
Your app. Some products have a legitimate reason to force one clock: aviation, healthcare shift rosters, transit timetables, or any screen where "12:30" without AM/PM is dangerous. That is a product decision, and it should be explicit and named in code rather than an accident of a hard-coded pattern.
So the locale sets the default, the user can override it, and the app overrides both only on purpose. The locale only sets the default clock, so follow the user's device override on mobile and offer an explicit in-app clock setting on the web, where that override is invisible. An app with perfect locale data can still show the wrong clock to one person if it skips that override.
Why hard-coded patterns break
Practitioner threads have reported the same failures for more than a decade.
A fixed display pattern ignores both locale and user. "h:mm a" gives AM/PM to German, Japanese, and French readers. "HH:mm" gives "14:30" to US readers who expect "2:30 PM". Translators cannot fix this, because the pattern lives in code, not in the string files.
On iOS a fixed pattern can change under you. QA1480 says the 24-Hour Time override causes NSDateFormatter to rewrite the format string you set, which can make time parsing fail. A Stack Overflow question with more than 50,000 views calls this the NSDateFormatter locale "feature": a yyyyMMddHHmmss format works for most users until someone with the override runs it. The opposite case is reported too. In another question, a formatter set to "h:mm a" prints 24-hour output once the switch is on, and the asker wants to know how to support the setting deliberately rather than by side effect.
Using a time style does not guarantee every surface agrees. A 2022 report describes a SwiftUI app that kept AM/PM for French (Canada) while the system sample and stock apps used 24-hour time. That is one author's report, so treat it as a reason to test the exact locale and region combinations you ship rather than only "French".
On the web there is no API for the operating system's clock setting. A JavaScript question with more than 11,000 views asks how to detect whether the user's machine uses a 12-hour or 24-hour clock and notes that guessing from locale lists fails, for example when a browser sends plain en. Native form controls do not help either. The WHATWG issue on <input type=time>, open since 2021, quotes the HTML specification: the browser translates the value to the user's preferred presentation, and authors cannot force a 24-hour display.
The hour12: false trap
Many JavaScript tutorials reach for hour12: false to get a 24-hour clock. Its output depends on both the engine and the locale.
There are four hour cycles. h12 runs 1 to 12 and h11 runs 0 to 11, both with a day period. h23 runs 0 to 23 and h24 runs 1 to 24. Only h12 and h23 match what people expect on a clock face or a departure board. h11 writes midnight as "0:30 AM" and h24 writes it as "24:30".
MDN's Intl.DateTimeFormat() reference documents that hour12: false sets hourCycle to h23, and that hour12 overrides both the hc locale extension and the hourCycle option. Runtimes in the field have not always behaved that way. A Stack Overflow report shows Chrome formatting 23:59 UTC in Prague as "24:59" with hour12: false. We checked Node v20.19.2 (ICU 76.1) by formatting 00:54 in Europe/Helsinki:
| Locale | Default | hour12: false |
hourCycle: 'h24' |
-u-hc-h23 |
|---|---|---|---|---|
| en-US | 12:54 AM | 24:54 | 24:54 | 00:54 |
| en-GB | 0:54 | 0:54 | 24:54 | 0:54 |
| ko-KR | 오전 12:54 | 24:54 | 24:54 | 00:54 |
| ja-JP | 0:54 | 0:54 | 24:54 | 0:54 |
The locales whose default is already 24-hour look fine with hour12: false. The locales that default to 12-hour, which are exactly the ones you are trying to switch, produce "24:54". Mobile JavaScript engines add their own variance: meta/hermes issue #2209, opened in September 2026 and still open, reports Hermes on Android resolving h11 and h24 but formatting midnight with the opposite cycle's hour.
Phrase's guide does not warn about this either. Phrase's date and time localization guide uses hourCycle: "h24" in its own example, which renders midnight as 24 in every locale.
Treat hour12: false as unreliable and request hourCycle h23 or h12 by name, because engines still disagree on what hour12 resolves to at midnight. What to do instead:
// Force a 24-hour clock only when the product or the user asks for it.
function timeFormatter(locale, clockSetting /* 'auto' | 'h12' | 'h23' */) {
const options = { hour: 'numeric', minute: '2-digit' };
if (clockSetting === 'h12' || clockSetting === 'h23') {
options.hourCycle = clockSetting; // never hour12, never h24 or h11
}
return new Intl.DateTimeFormat(locale, options);
}
If you prefer to carry the choice in the locale itself, the -u-hc- Unicode extension works too: MDN's Intl.Locale.prototype.hourCycle shows fr-FR-u-hc-h23. Do not combine it with hour12, which wins over both. To read a locale's preferred cycles, call Intl.Locale.prototype.getHourCycles(); MDN notes that some browser versions shipped it as an hourCycles accessor, so feature-detect both.
Implement it on the web
- Default to the locale. Pass only
hourandminute(andtimeStyle: 'short'if you prefer) and let the locale's CLDR data choose the cycle. Do not addhour12"to be safe". - Add a clock setting. Because the browser cannot see the operating system toggle, put "Automatic, 12-hour, 24-hour" next to language in your settings and store it with the user profile, not the device. Map the choice to
hourCycle: 'h12'or'h23'. - Use one formatter factory. Every time label, including chat timestamps, calendar grids, and email previews generated on the server, should call the same function so the setting cannot be honored on one screen and ignored on the next.
- Format server-side with the same inputs. If your backend renders notification text or emails, send the user's locale and clock setting with the job. A server running in en-US will otherwise apply its own default.
- Accept native picker behavior. If you use
<input type=time>, its display follows the browser. Either accept that or build a custom picker that reads your clock setting. Do not try to restyle the native control into a different cycle.
Implement it on iOS
QA1480 tells you to avoid setting a fixed format string for user-visible dates. Use date and time styles, or generate the pattern from a template.
let formatter = DateFormatter()
formatter.locale = appLocale // the app's effective locale
formatter.setLocalizedDateFormatFromTemplate("jmm")
let label = formatter.string(from: date)
The j symbol carries the preference. UTS 35 reserves j for skeletons passed to pattern generation APIs, where it requests the locale's preferred hour format and is replaced by h or H before matching. The specification says using j in a skeleton is the only way for a skeleton to request the locale's preferred cycle. Apple's setLocalizedDateFormatFromTemplate(_:) and dateFormat(fromTemplate:options:locale:) generate a pattern arranged for the locale. If you need the pattern string for a custom view, use the class method and keep the result rather than hand-editing it.
If your app has its own language setting, pass that locale to the formatter. Then test with the 24-Hour Time switch both on and off, because the override comes from the device, not from your locale value. A long-running question shows how easy it is to combine relative dates ("Today") with a hand-built time and lose the setting. Build the whole label through formatters instead of concatenating a time onto a translated word.
Implement it on Android
Android gives you the user's choice directly, so use it.
val is24 = DateFormat.is24HourFormat(context)
val skeleton = if (is24) "Hm" else "hm"
val pattern = DateFormat.getBestDateTimePattern(appLocale, skeleton)
val label = SimpleDateFormat(pattern, appLocale).format(date)
DateFormat.getBestDateTimePattern(Locale, String) returns the best localized form of a skeleton for a locale, so day-period position and separators still follow the language. The reference also documents getTimeFormat(Context), which formats times according to the context's locale and the user's 12-hour or 24-hour preference, if you do not need a custom skeleton. Picking Hm or hm from is24HourFormat is our recommendation for custom labels, because it keeps the user's override and the app locale in one place.
For pickers, set the mode explicitly. The TimePicker widget has setIs24HourView(Boolean); pass the same is24 value. A Stack Overflow report describes a picker that stayed in the same hour format after the developer switched the locale from English to Italian, because is24HourFormat kept returning the same value.
If your Android app is written in React Native, test the Hermes engine separately. The open Hermes issue above means Intl output for h11, h24, and hour12 can differ from Chrome or a WebView in the same app.
Keep display and machine formats apart
Keep display and machine time formats on separate formatters, because the iOS 24-Hour Time switch rewrites fixed patterns and breaks parsing of strings you formatted for display. Every bug in this guide gets worse when one formatter serves both people and parsers.
QA1480 recommends en_US_POSIX for fixed-format strings because it yields US English results regardless of user and system preferences and does not change over time. Use it, or ISO 8601 with a dedicated formatter, for API payloads, logs, cache keys, and deep links. Use the locale-aware formatter only for text people read.
Two habits follow from this:
- Never parse a string you formatted for display. Keep the
Dateor timestamp in your view model and format at the edge. - Never store a time-of-day as "2:30 PM". Store minutes since midnight or an ISO time, and treat the clock format as presentation.
Translated strings that contain times
Times rarely appear alone. "Your table is ready at {time}" and "Reminder set for {time}" are translated sentences with a placeholder. Keep the time as a placeholder and format it before substitution, using the same formatter factory. Do not write "at {hour}:{minute} {ampm}" into a source string, because translators cannot change the clock and some languages do not use a day period at all.
If you translate with i18nAgent or any other system, check that placeholders survive untouched and that no translator was asked to localize "AM" and "PM" as standalone keys. Day-period words belong to CLDR data, not your string catalog.
Failure handling and tradeoffs
- Unknown setting. If the profile has no clock setting yet, use "automatic" and the locale default. Do not infer 12-hour from an English language code.
- Missing locale data. If a formatter throws or returns an unexpected pattern for a rare locale, fall back to the locale's language with the user's clock setting, not to a fixed English pattern.
- Mixed surfaces. Widgets, notifications, and watch faces may be rendered by a different process. Pass the clock setting into those processes explicitly, or read
is24HourFormatfrom the right context. - Forced 24-hour screens. If a product screen must always use 24-hour time, document it in the formatter call (
hourCycle: 'h23',Hm) and keep the rest of the app on the user preference. A timetable in 24-hour time is a reasonable product rule. A chat app that ignores the phone setting is a bug.
Verify the clock format before you ship
Build a small test matrix rather than checking one language by eye:
- Format 00:05, 12:05, and 23:55 in each launch locale. Assert that no output contains "24:" and that 12-hour locales show the correct day period at midnight and noon.
- Run the same cases with the clock setting forced to
h12andh23, including en-US withh23and de-DE withh12. - On iOS, run the UI test suite with 24-Hour Time on and off. On Android, toggle "Use 24-hour format" and check every time label and picker.
- Run the JavaScript cases in each engine you ship: desktop browsers, the mobile WebView, Node on the server, and Hermes if you use React Native.
- Grep the codebase for display patterns containing
h:mm,HH:mm,a", andhour12. Each hit should be either a machine format with a fixed locale or a deliberate, commented override.
Compare against the formatter's own output for expected values where you can, because CLDR updates can change separators and day-period wording.
Common mistakes
- Using
hour12: falseto force 24-hour time and shipping "24:05" to US users at midnight. - Copying
hourCycle: 'h24'from an example without checking what midnight looks like. - Deriving the clock from the language code, so en-GB users get AM/PM.
- Hard-coding
HH:mmfor parsing on iOS and breaking when the 24-Hour Time switch changes. - Putting "AM" and "PM" in the string catalog.
- Honoring the user setting in the app but not in notifications or emails.
What to do next
Search your codebase for hour12, h:mm a, and HH:mm today and sort every hit into "display" or "machine". Replace display patterns with the locale default plus an explicit h12 or h23 setting, then add the midnight test above to CI before the next release. If you are also fixing date order and number formats, the companion guide on localizing app dates, times, and numbers covers the rest of the formatting layer.
