Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get system time format(24 or 12 AM/PM) in Flutter?

Tags:

flutter

How can I detect current time format that is set on users phone (12 AM/PM or 24 hrs)?

There is native Android method

DateFormat.is24HourFormat(context);

but I cant find similar in Flutter

like image 204
kashlo Avatar asked Jul 09 '19 18:07

kashlo


People also ask

How do you get the 12 hour format in Flutter?

Flutter Convert TimeOfDay to 24 hours format | Technical Feeder. final time = TimeOfDay(hour: 21, minute: 12); time. toString(); // TimeOfDay(21:12) We expect that it returns hh:mm format but actually not. TimeOfDay has format method that converts to 12 hours format.

How do you get only AM or PM in Flutter?

How do you get AM PM from time in Flutter? DateTime now = DateTime. now(); String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').

How do I change time format on Flutter?

To format DateTime in Flutter using a standard format, you need to use the intl library and then use the named constructors from the DateFormat class. Simply write the named constructor and then call the format() method with providing the DateTime.


1 Answers

bool is24HoursFormat = MediaQuery.of(context).alwaysUse24HourFormat;

Docs here

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.

like image 191
Denis G Avatar answered Sep 29 '22 09:09

Denis G