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

McBgnr

macrumors regular
Original poster
Apr 13, 2009
144
0
Hello,

I am trying to get the date from a dateString using the following code snippet:

Code:
NSDate *dateToday = [NSDate date];
	NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
	[dateFormat setDateFormat:@"MMM d, YYYY"];
	NSString *sDate = [dateFormat stringFromDate:dateToday];
	NSLog(sDate);
	
	NSDate *newDate = [dateFormat dateFromString:sDate];
	
	NSString *newDateString = [dateFormat stringFromDate:newDate];
	NSLog(newDateString);

But the value that is getting logged for newDateString is Dec 22, 2008 instead of today's date. Am I missing something in my code? Suggestions are welcome.
 
'Y' is for non-Gregorian ISO week date

The 'Y' format specifier is for the ISO week date, a governmental and fiscal calendar that has 364 or 371 days in a year so as to be evenly divisible into weeks. Use 'y' for the Gregorian year. The Unicode date format specs (tr35-4 for OS 10.4 and tr35-6 for 10.5) give the meaning of the 'Y' and 'y' format characters.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.