Last active
September 12, 2017 06:36
-
-
Save EddyVerbruggen/ee131a16c5ebd35f58b69fe72acb9128 to your computer and use it in GitHub Desktop.
Determine whether or not an iOS or Android device is running in 24 hour format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ad } from "tns-core-modules/utils/utils"; | |
import { isIOS } from "tns-core-modules/platform"; | |
let is24HourFormat: boolean; | |
if (isIOS) { | |
// solution from https://stackoverflow.com/a/12236693/2596974 | |
const dateFormat: string = NSDateFormatter.dateFormatFromTemplateOptionsLocale("j", 0, NSLocale.currentLocale); | |
is24HourFormat = dateFormat.indexOf("a") === -1; | |
} else { | |
// https://developer.android.com/reference/android/text/format/DateFormat.html#is24HourFormat(android.content.Context) | |
is24HourFormat = android.text.format.DateFormat.is24HourFormat(ad.getApplicationContext()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment