Skip to content

Instantly share code, notes, and snippets.

@mortenjust
Created February 15, 2016 07:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenjust/74a5b0d7226339cd0171 to your computer and use it in GitHub Desktop.
Save mortenjust/74a5b0d7226339cd0171 to your computer and use it in GitHub Desktop.
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