I would like to check if the user has selected the 12-hour or 24-hour clock as their preference in OS X and iOS. So I would like to detect if the user has done the following:
- On the Mac, the System Preference is in Date & Time, Use a 24-hour Clock
- On the iPhone, the Preference is in Settings, General, Date & Time, 24-Hour Time
I currently have the following code but it always returns the time as represented by the 12-hour clock, even if the system preference set by the user is for the 24-hour clock.
let timeFormatter = NSDateFormatter()
timeFormatter.locale = NSLocale.currentLocale()
timeFormatter.dateStyle = NSDateFormatterStyle.NoStyle
timeFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
let ampmtext = timeFormatter.stringFromDate(NSDate())
println(ampmtext)
if ampmtext.rangeOfString("M") != nil {
println("12-hour clock")
} else {
println("24-hour clock")
}
I would like to find a solution written in Objective-C and Swift for both the Mac and iPhone that can detect if the device clock displays 24-hour or 12-hour time.