I'm having a strange issue with a NSDateFormatter. Off course I'm doing something wrong here, but I can't figure out what it is, must be something small and stupid...
I have a date I want to format. The date is 2012-05-06 16:52:40 and is contained in an NSDate object, it is properly initialized, I checked that in the debugger.
The following code however:
NSLog(@"%@", [myDate description]);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"dd-MM-yyyy";
NSString *myDateAsString = [dateFormatter stringFromDate:myDate];
NSLog(@"%@", myDateAsString);
prints:
2012-05-06 16:52:40
(null)
I really don't see the error in my code. Any hints?
myDate is actually an NSString and not an NSDate. Otherwise, the description would contain the time zone too: 2012-05-06 16:52:40 +0000.
Try the following to check that:
NSLog(@"%@", [myDate class]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With