"24 Hour Format" setting


#1

Hi!

Is there a way, from NativeScript, to know if the user has “24 Hour Format” set on his phone?

Thanks,
Shay.


#2

I’m not sure if there’s a plugin for that, but you could add a little utility class to your project that checks it.

Android:

import getApplicationContext = ad.getApplicationContext;
const is24h = android.text.format.DateFormat.is24HourFormat(getApplicationContext());

iOS:

const dateFormat: string = NSDateFormatter.dateFormatFromTemplateOptionsLocale("j", 0, NSLocale.currentLocale);
const is24h = dateFormat.indexOf("a") === -1

Here, have a Gist:


#3

Brilliant! It works like a charm!