Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func usesAMPM() -> Bool {
let locale = NSLocale.currentLocale()
let dateFormat = NSDateFormatter.dateFormatFromTemplate("j", options: 0, locale: locale)!
if dateFormat.rangeOfString("a") != nil {
return true
}
else {
return false
}
}
func hourInLocalFormat(hour:Int) -> String {
let currentTimeFormatter = NSDateFormatter()
currentTimeFormatter.dateFormat = "HH"
let date2 = currentTimeFormatter.dateFromString("\(hour)")
let formatter = NSDateFormatter()
if usesAMPM(){
formatter.dateFormat = "h aa"
} else {
formatter.dateFormat = "H"
}
return formatter.stringFromDate(date2!)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.