I have a date in string like
NSString Date = "Dec 21 2011";
I want to convert that string into date
as my date has special format so i am utilizing like that:
`NSDateFormatter *dateFormatterTest = [NSDateFormatter new];
[dateFormatterTest setDateFormat:@"MMM dd YYYY"];
fromDate = [dateFormatterTest dateFromString:Date];
NSLog("%@",fromDate);
I am getting this log
2010-12-18 19:00:00 +0000
Can any one explain how can i get correct date.
You need to use lowercase
yyyyin your date format:The output with this new date format is this:
Aside from that (main problem), you need to fix the following things:
NSString *date@"Dec 21 2011"NSDate *fromDate =…NSLog(@"%@",fromDate);Your code should now look like this:
Note I have renamed
Dateto being lowercase because it is conventional that you name instances in such a way as it avoids confusing them with classes.