1

When I read the start time for an event using the JSON output for Google calendar I get the time in this format "2009-03-05T10:46:25.245Z". How can I convert this to meaning full date and time in iPhone SDK?

Thanks in advance.

John Conde
  • 217,595
  • 99
  • 455
  • 496
bp581
  • 859
  • 1
  • 16
  • 47

1 Answers1

0

I think this post has your answer: Nil NSDate when trying to get date from UTC string in zulu time

This seems to work for me:

NSString *timeValue = @"2009-03-05T10:46:25.245Z";
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate* date = [df dateFromString:[timeValue stringByReplacingOccurrencesOfString:@"Z" withString:@"-0000"]];
NSLog(@"The date is: %@",date);
Community
  • 1
  • 1
Michael Petrov
  • 2,247
  • 15
  • 15
  • Thanks for the response. Unfortunately no luck. NSString *timeValue has the value 2009-03-05T10:46:25.245Z. Can you give me sample code to convert this variable....appreciate it . – bp581 Dec 23 '10 at 20:33
  • Take a look at my edit above, I just run it in the sim and it worked fine. The key is replacing the Z with "-0000". – Michael Petrov Dec 23 '10 at 20:41