1

What kind of format is 2012-05-02T15:44:20.000Z

I've been trying to get it to parse, but having some issues with this section.

NSString *articleDateString = [item valueForChild:@"published"];
        NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
        NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateStyle:NSDateFormatterShortStyle];
        NSString *dateofarticle = [dateFormatter stringFromDate:articleDate];

It is not RFC822. That's about all I know.

user717452
  • 33
  • 14
  • 73
  • 149
  • Post your code so we can help. – rmaddy Jan 21 '13 at 04:31
  • Since you have a fixed format date/time, you can't use the standard date and time styles. You need to provide an explicit date format. There must be dozens of existing questions covering this. – rmaddy Jan 21 '13 at 04:34
  • Check this question. http://stackoverflow.com/questions/8876954/whats-the-most-simplest-way-to-parse-rfc3339-date-string-in-ios – iDev Jan 21 '13 at 04:35
  • 4
    its an ISO 8601 datetime format, refer same post at http://stackoverflow.com/questions/2201216/is-there-a-simple-way-of-converting-an-iso8601-timestamp-to-a-formatted-nsdate – Cris Jan 21 '13 at 04:42
  • Someone had answered correctly as I see the answer in my Inbox, but it is no longer here for me to accept. – user717452 Jan 21 '13 at 20:41

1 Answers1

0
NSString *articleDateString = [item valueForChild:@"published"];
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"];
NSString *dateofarticle = [dateFormatter stringFromDate:articleDate];
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184