I'm trying to format time as follows:
let formatter = NSDateFormatter()
formatter.dateFormat = "hh_mm_ss"
let d = formatter.stringFromDate(NSDate())
println("formatted text is: \(d)")
Suppose that current time is Sep 3, 2014 22:15:30
22_15_30
. 22:15:30
I'm using xcode 6 beta 5... Am I missing something? Why stringFromDate doesn't return the correct date formatted?
EDIT : I'm using xcode 6 beta 6.
Thanks!
The 24-hour format is "HH", not "hh".
The reason that it works in the Playground may be that user defined settings can override the 12/24-format choice, compare What is the best way to deal with the NSDateFormatter locale "feechur"? . To be on the safe side, set the "en_US_POSIX" locale for the date formatter:
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
// Swift 3:
formatter.locale = Locale(identifier: "en_US_POSIX")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.