I am trying to parse a date that is sent to the server.
Now the date that is recieved from the server is "2016-05-10T22:34:00.000Z"
And here is my code to get a formatted date out of the above date string :
let format="yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let dateFmt = NSDateFormatter()
dateFmt.dateFormat = format
let newreadableDate = dateFmt.dateFromString(dateString)
print(newreadableDate!)
dateFmt.dateFormat = "MMM dd hh:mm a"
print("Formatted date is : \(dateFmt.stringFromDate(newreadableDate!))")
The print statement prints the following result : May 11 04:04 AM
The above result is totally wrong. I should get back the same date that I recieved from server but with different format.
But the newReadableDate variable prints the correct date : 2016-05-10 22:34:00 +0000
But after I format it, it gives me wrong date.
What is wrong in the above code ?