I'm having trouble converting an ISO 8601 timestamp into an NSDate
. I tried to use NSDateFormatter
, but I can't get it to work with the UTC time offset that appears on the end of the timestamps. To explain, I would like to convert a timestamp such as the following into an NSDate
: 2011-03-03T06:00:00-06:00
. My question is: How do I deal with the "-06:00" part? I tried using yyyy-MM-dd'T'HH:mm:ssZ
as my date format string but it doesn't work. Any suggestions?
相关问题
- Check if NSDate is in this week or next week
- Converting Date with Time in PST into UTC format
- Changing background according to time - Objective
- Given an ISO 8601 week number, get date of first d
- How to add th and st in Date Format
相关文章
- UTC Time Assignment in VBScript
- Number of seconds since the beginning of the day U
- Escape NSDateFormatter String
- How to format a date like “5 min”, “1 hour,”, “Yes
- NSDateFormatter not behaving properly when convert
- LLDB display of NSDate is inconsistent?
- Swift 2 for loop low and high date between
- How to get Date from String in swift 3?
In my case I received something like that:
"2015-05-07T16:16:47.054403Z"
And I had to use:
"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSSZ"
The problem is the
:
character inside the timezone offset. You could explicitly remove just that colon, or remove all of the colons, and then proceed. For example:This logs:
No need to remove the :'s. To handle the "00:00" style timezone, you just need "ZZZZ":
Swift
Objective-C
Converting ISO 8601 timestamp into NSDate In Swift:
Or optional explicitly:
Here is the method that I use: