I need to access the device settings of an iOS device from code and get the settings that specifies if the time is displayed as 12hour or 24hour format. I could use the "NSLocale.CurrentLocale" property but that just has the default time format of given locale, not the device settings, doesn't it? I haven't found and related info online, so I'm asking for help here.
Asked
Active
Viewed 913 times
3
-
The documentation seems clear. Isn't it? https://developer.apple.com/documentation/foundation/nslocale/1409990-currentlocale – Dorukhan Arslan Dec 05 '17 at 12:18
-
Ok, then it might reflect the 24/12 format, but still, I don't see the property to check what format is used. I need to get something like bool Use24HourFormat = (check if 24 hour format is set). – Tomáš Bulíček Dec 05 '17 at 12:35
1 Answers
6
Try this code for iOS:
private bool CheckIsTwelveTimeFormat()
{
var dateFormatter = new NSDateFormatter();
dateFormatter.DateStyle = NSDateFormatterStyle.None;
dateFormatter.TimeStyle = NSDateFormatterStyle.Short;
var dateString = dateFormatter.ToString(NSDate.Now);
var isTwelveHourFormat =
dateString.Contains(dateFormatter.AMSymbol) ||
dateString.Contains(dateFormatter.PMSymbol);
return isTwelveHourFormat;
}
And this for android:
private bool CheckIsTwelveTimeFormat()
{
return Android.Text.Format.DateFormat.Is24HourFormat(Android.App.Application.Context);
}

Patrick
- 1,717
- 7
- 21
- 28

Alexander Budiakov
- 61
- 1
- 2