How can I convert string date to NSDate?

前端 未结 18 1710
花落未央
花落未央 2020-11-22 16:14

I want to convert \"2014-07-15 06:55:14.198000+00:00\" this string date to NSDate in Swift.

18条回答
  •  忘了有多久
    2020-11-22 16:44

    import Foundation
    
    let now : String = "2014-07-16 03:03:34 PDT"
    var date : NSDate
    var dateFormatter : NSDateFormatter
    
    date = dateFormatter.dateFromString(now)
    
    date // $R6: __NSDate = 2014-07-16 03:03:34 PDT
    

    https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/index.html#//apple_ref/doc/uid/20000447-SW32

提交回复
热议问题