-1

How can I turn 2016-07-05 22:13:48 +0000 into an NSDate? I don't know which format is to used, I have no idea what the +0000 is for. Is there any convenient way to to use that input string directly to make an NSDate object in Swift?

Tommy K
  • 1,759
  • 3
  • 28
  • 51
  • 1
    Possible duplicate of [iPhone NSDateFormatter Timezone Conversion](http://stackoverflow.com/questions/3094730/iphone-nsdateformatter-timezone-conversion) – Ozgur Vatansever Sep 07 '16 at 06:21

1 Answers1

1

You can use NSDateFormatter like this.

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss z"
let date = dateFormatter.dateFromString("2016-07-05 22:13:48 +0000")
print("Date is - \(date)")

Output

enter image description here

Nirav D
  • 71,513
  • 12
  • 161
  • 183
  • Here date is `NSDate` object. – Nirav D Sep 07 '16 at 06:28
  • Also +0000 is used with timezone hour specification and its formatter is `z/Z` . For more detail about formatter check this link http://waracle.net/iphone-nsdateformatter-date-formatting-table/, Check the zone section in the link. – Nirav D Sep 07 '16 at 06:35