Created
February 15, 2016 07:33
-
-
Save mortenjust/74a5b0d7226339cd0171 to your computer and use it in GitHub Desktop.
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
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