sleepwalkerfx sleepwalkerfx - 1 month ago 5
Swift Question

correct format for Swift NSDateFormatter

I have this time format 2016-09-06T12:44:00.118Z

What is the correct format for NSDateformatter? With below format it doesn't seems to be calculating the correct time.

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

This last 118Z part of the date string is probably the time zone. So What dateFormat could be used here instead .SSSZ ?

I couldn't find a way to construct a proper formatter string with the help of this,


Try this...

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(name: "UTC")