Skip to content

Instantly share code, notes, and snippets.

@EddyVerbruggen
Last active September 12, 2017 06:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddyVerbruggen/ee131a16c5ebd35f58b69fe72acb9128 to your computer and use it in GitHub Desktop.
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
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