I have the following code which is simply getting the current date and converting it to the format YYYY-MM-dd HH:mm:ss zzz
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"YYYY-MM-dd HH:mm:ss zzz"];
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
[dateFormatter setTimeZone:currentTimeZone];
NSString *time = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"TIME IS %@", time);
With this, I'm getting the following log output:
2014-12-30 00:20:38.987 MYAPPNAME[953:229825] TIME IS 2015-12-30 00:20:38 CST
Can someone tell me why the output is showing as 2015, rather than 2014 as it should be?
yyyy specifies the calendar year, whereas YYYY specifies the year (of “Week of Year”)
you must change your dateformatter style from
[dateFormatter setDateFormat: @"YYYY-MM-dd HH:mm:ss zzz"];
to
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"];
for your reference, check this apple documentation
change your date formate
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"];
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