Tag: iso8601

NSDateFormatter seems to have the wrong month

I have this block of code to read in the ISO 8601 Date/Time specification. The problem is that for some reason, the month doesn’t work. Every time I convert it month is “01”. What am I doing wrong? NSDateFormatter *UTCDateFormat = [[NSDateFormatter alloc] init]; [UTCDateFormat setDateFormat:@”yyyy-MM-DD’T’HH:mm:ss’Z'”]; [UTCDateFormat setTimeZone:[NSTimeZone timeZoneWithName:@”UTC”]]; [UTCDateFormat setCalendar:[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]]; [UTCDateFormat […]

How to parse an ISO-8601 duration in Objective C?

I’m looking for an easy way to parse a string that contains an ISO-8601 duration in Objective C. The result should be something usable like a NSTimeInterval. An example of an ISO-8601 duration: P1DT13H24M17S, which means 1 day, 13 hours, 24 minutes and 17 seconds.

Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?

If I use the following code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm”]; NSDate *myDate = [dateFormatter dateFromString:@”2010-01-28T15:22:23.863″]; NSLog(@”%@”, [dateFormatter stringFromDate:myDate]); It is successfully converted to a Date object, however, I cannot seem to format it any other way than yyyy-MM-dd’T’HH:mm, i.e. what gets logged is 2010-01-28T15:22:23 If I change the dateFormat to say […]

Swift: how to create a date time stamp and format as ISO 8601, RFC 3339, UTC time zone?

How to generate a date time stamp, using the format standards for ISO 8601 and RFC 3339? The goal is a string that looks like this: “2015-01-01T00:00:00.000Z” Format: year, month, day, as “XXXX-XX-XX” the letter “T” as a separator hour, minute, seconds, milliseconds, as “XX:XX:XX.XXX”. the letter “Z” as a zone designator for zero offset, […]

Parsing ISO 8601 with NSDateFormatter

I’ve read through the various posts on SO about this, but have still not solved the problem. Here’s the string that I’m trying to parse into an NSDate object: 2012-04-08T12:00:00.00+02:00 I understand that the problem is the time zone format. Here’s the date format string that I’m trying: yyyy-MM-dd’T’HH:mm:SSZZZZ Thanks for any help.

How to parse an ISO8601 date

This question already has an answer here: How to parse a date string into an NSDate object in iOS? 7 answers

What's the right way to parse an ISO8601 date in cocoa?

I would like to parse ISO8601 dates in Cocoa, both for iOS 4+ and OSX 10.6+ There are a few questions about this on StackOverflow already, but in my opinion none of them contain good answers. Here’s what I think constitutes a good answer: The answer should point to code with support for ISO8601. This […]

In what format is this date string?

Im trying to convert a bunch of NSStrings into NSDate objects. Here is an example string: 2013-04-25T15:51:30.427+1.00 But I can’t figure out what format it is in, so far I have (The question marks are the bits I’m stumped with): yyyy-MM-ddTHH:mm:ss????zzz The main problem I’m having is with the ‘.427’ part although if I’m making […]

How do I get an ISO 8601 date on iOS?

It’s easy enough to get the ISO 8601 date string (for example, 2004-02-12T15:19:21+00:00) in PHP via date(‘c’), but how does one get it in Objective-C (iPhone)? Is there a similarly short way to do it? Here’s the long way I found to do it: NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; dateFormatter.dateFormat = @”yyyy-MM-dd’T’HH:mm:ssZ”; NSDate […]