DEV Community

HarmonyOS
HarmonyOS

Posted on

How to Check Whether the System Time is 24-Hour Format?

Read the original article:How to Check Whether the System Time is 24-Hour Format?

Question

How to Check Whether the System Time is 24-Hour Format?

Short Answer

With using is24HourClock9+

  • static is24HourClock(): boolean
  • Determine whether the system time is in 24-hour format.
  • Card capabilities : Starting from API version 11, this interface supports use in ArkTS cards.
  • Meta-service API: Starting from API version 12, this interface can be used in meta-services.
  • System Capability : SystemCapability.Global.I18n
  • Return value:

image.png

Example:

let  is24HourClock : boolean = i18n.System.is24HourClock (); // Is the system 24-hour switch turned on ?
Enter fullscreen mode Exit fullscreen mode

Applicable Scenarios

  • When your application displays time-sensitive data and needs to match the user’s system preference (12-hour or 24-hour).
  • In internationalized apps that adapt UI based on locale and time settings.
  • When developing widgets, cards, or meta-services that need consistent time display across devices and services.

Written by Emine INAN

Top comments (0)