carboncomputed
carboncomputed

Reputation: 1620

How to parse date with NSDateFormatter with timezone?

This is the date format I'm getting back from the server:

Tue Apr 05 2016 23:59:00 GMT-0700 (PDT)

This is what I have so far: "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzz)"

Which characters are having trouble parsing?

Upvotes: 1

Views: 426

Answers (1)

Ozgur Vatansever
Ozgur Vatansever

Reputation: 52133

Date format should be the following:

"EEE MMM dd yyyy HH:mm:ss 'GMT'ZZZZ (zzz)"

Demo:

let dateString = "Tue Apr 05 2016 23:59:00 GMT-0700 (PDT)"
let formatter = NSDateFormatter()
formatter.dateFormat = "EEE MMM dd yyyy HH:mm:ss 'GMT'ZZZZ (zzz)"

let date = formatter.dateFromString(dateString)
print(date)
>>> Optional(2016-04-06 06:59:00 +0000)    

Upvotes: 0

Related Questions