McBgnr
May 6, 2009, 05:39 AM
Hello,
I am trying to get the date from a dateString using the following code snippet:
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.
I am trying to get the date from a dateString using the following code snippet:
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.
