Evgeniy Kleban Evgeniy Kleban - 4 months ago 7
iOS Question

Cant get current date yyyy-mm-dd

I can't figure out what i'm doing wrong.
Trying get NSString with current date with format

yyyy-mm-dd
.

_convenienceFormatter = [[NSDateFormatter alloc] init];
_convenienceFormatter.dateFormat = @"yyyy-mm-dd";
NSString *string = [_convenienceFormatter stringFromDate:[NSDate date]];


Output is : 2016-37-14

What am i doing wrong?

Answer

I tried your coding

NSDateFormatter *convenienceFormatter = [[NSDateFormatter alloc] init];
convenienceFormatter.dateFormat = @"yyyy-mm-dd";
NSString *string = [convenienceFormatter stringFromDate:[NSDate date]];

It gives me 2016-14-14

NSDateFormatter *Formatter = [[NSDateFormatter alloc] init];
Formatter.dateFormat = @"yyyy-MM-dd";
NSString *stringFor = [Formatter stringFromDate:[NSDate date]];

But above code gives me 2016-07-14

NOTE: Generally mm indicates minutes.MM indicates month

Date Formatting Table

Dates

Date Programming

Date Formatter

Comments