Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ross.32

macrumors 6502
Original poster
May 27, 2007
259
0
Using this code here, NSDateFormatter is returning the year as 2010. Anyone else experiencing this?

Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"YYYYMMddHHmm"];
NSString *dateString = [[NSString alloc] initWithFormat:@"%@", [dateFormatter stringFromDate:[NSDate date]]];
//NSLog(@"The dateString = %@", dateString);
[dateFormatter release];
 

bredell

macrumors regular
Mar 30, 2008
127
1
Uppsala, Sweden
Using this code here, NSDateFormatter is returning the year as 2010. Anyone else experiencing this?

Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"YYYYMMddHHmm"];
NSString *dateString = [[NSString alloc] initWithFormat:@"%@", [dateFormatter stringFromDate:[NSDate date]]];
//NSLog(@"The dateString = %@", dateString);
[dateFormatter release];

That's correct. The date format specifier "Y" gives you the year number to be used in combination with week numbers. In UTC we're currently on week 1 2010, that's why the "YYYY" format returns "2010". If you want the ordinary year you should use "yyyy".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.