You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First putting the 'Z' in single quotes seems to escape it so that it always assumes the date string is in GMT therefore ignoring timezone offset included in the string.
For example if I use ModelRocket to parse the following date string from my JSON: "2015-10-04T01:00:00.000Z"
I actually end up with: "2015-10-04T05:00:00.000Z"
This is because by default NSDateFormatter uses the local timezone of the device (in my case EST) so when this combines with the escaped Z the time is off by 4 hours.
This can be corrected by eliminating the single quotes around the Z so it accepts the offsets properly.
Additionally having the SSS means that the example string 2015-05-31T19:00:17+00:00 from the documentation will fail to parse because its missing milliseconds.
The last thing is that its recommended to add the following just in case the device is not using the gregorian calendar:
The current NSDateFormatter for transforming ISO8601 appears to have some issues with regards to the date format:
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
First putting the
'Z'
in single quotes seems to escape it so that it always assumes the date string is in GMT therefore ignoring timezone offset included in the string.For example if I use ModelRocket to parse the following date string from my JSON:
"2015-10-04T01:00:00.000Z"
I actually end up with:
"2015-10-04T05:00:00.000Z"
This is because by default NSDateFormatter uses the local timezone of the device (in my case EST) so when this combines with the escaped Z the time is off by 4 hours.
This can be corrected by eliminating the single quotes around the Z so it accepts the offsets properly.
Additionally having the
SSS
means that the example string2015-05-31T19:00:17+00:00
from the documentation will fail to parse because its missing milliseconds.The last thing is that its recommended to add the following just in case the device is not using the gregorian calendar:
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
ModelRocket/ModelRocket/JSONTransformable.swift
Line 83 in 866b1a7
The text was updated successfully, but these errors were encountered: