Evgeniy Kleban Evgeniy Kleban - 1 year ago 56
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


_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 Source

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


Date Programming

Date Formatter

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download