NSDateFormatter for datetime [duplicate]

孤者浪人 提交于 2019-12-20 07:41:12

问题


I have a string which is coming from an API that I need to convert into a NSDate but I'm uncertain which dateFormat to use for NSDateFormatter.

let openedAt = "2015-06-30T12:34:00.000-04:00" // coming from API

let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd..." // not sure what format to use here

if let date = formatter.dateFromString(openedAt) {
    println(date)
} else {
    println("NOPE!")
}

回答1:


try

 "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"

The Date Format Patterns guide suggests that "S" is the format specifier for fractions of seconds.



来源:https://stackoverflow.com/questions/31320382/nsdateformatter-for-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!