Reputation: 2627
How can I detect the current time format that is set on user's phone (12 AM/PM or 24 hrs)?
There is a native method in Android:
DateFormat.is24HourFormat(context);
but, I can't find similar in Flutter.
Upvotes: 12
Views: 9368
Reputation: 571
bool is24HoursFormat = MediaQuery.of(context).alwaysUse24HourFormat;
Doc here says:
Whether to use 24-hour format when formatting time.
The behavior of this flag is different across platforms:
On Android this flag is reported directly from the user settings called "Use 24-hour format". It applies to any locale used by the application, whether it is the system-wide locale, or the custom locale set by the application.
On iOS this flag is set to true when the user setting called "24-Hour Time" is set or the system-wide locale's default uses 24-hour formatting.
Upvotes: 25