Simple case of trying to prove I can convert NSString to NSDate. Create an NSDate, turn it into an NSString, then back into an NSDate. The date looks fine as a string, but when I convert it back I always get some date like 12/25/2011 …. Can someone spot my error?
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/YY hh:mm a"];
NSDate* b = [[NSDate alloc] init];
NSString* f = [df stringFromDate:b]; // has the current date and time
NSDate* dt =[df dateFromString:f]; // 12/25/2011 - where does it get this?
Try to use the following:
This is the result:
If you need more info I suggest to read date-formatter-examples.
If you don’t use ARC make attention to memory leaks. For example, use
[NSDate date]instead of[[NSDate alloc] init].Hope that helps.