Here is my class method for parsing a NSString
to a NSDate
object. Here is the code:
+ (NSDate *) stringToDate:(NSString *) string { NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.AAA Z"]; NSDate *date = [dateFormatter dateFromString:string]; NSLog(@"stringToDate(\"%@\") = '%@'", string, date); [dateFormatter release]; return date; }
and running it i get the following output:
stringToDate("2011-07-07 16:26:07.000 +0200") = '2011-07-06 22:00:00 +0000' stringToDate("2011-07-07 16:26:17.000 +0200") = '2011-07-06 22:00:00 +0000'
... the same output! Can you help me?