I am trying to parse an RSS feed, but the date is hard to parse. The date string is: publishedDate = "2013-01-08T20:09:02.000Z"
Here is my code:
NSDateFormatter *utc = [[NSDateFormatter alloc] init];
[utc setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSDate *dtUTC = [utc dateFromString: publishedDate];
NSDateFormatter *dfLocal = [[NSDateFormatter alloc] init];
[dfLocal setDateFormat:@"yyyy-MM-dd"];
[dfLocal setTimeZone:[NSTimeZone localTimeZone]];
NSString *time =[dfLocal stringFromDate:dtUTC];
NSLog(@"original UTC %@ now local: %@", dtUTC, time);
Why is date
returning nil? Also, i am trying to convert UTC time to CST Time.
For stime that includes miliseconds use "S".
NSLog output:
dtUTC: 2013-01-08 20:09:02 +0000
NSLog output:
original UTC 2013-02-08 20:09:02 +0000 now local: 2013-02-08
Use
Just change your time zone name to CST and change the setDateFormat as follows: