user6438311 user6438311 - 1 year ago 95
Objective-C Question

How to convert this date time string into only date?

I am getting this from the api

"created_at": "2016-08-16 05:05:22"
"updated_at": "2016-08-17 12:42:22"

but i want only date like this 16-july-2016.
How can i do this can any anyone tell me?

Answer Source
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; // or use yyyy-MM-dd HH:mm:ss
NSDate *date = [formatter dateFromString:@"2016-08-16 05:05:22"];
[formatter setDateFormat:@"dd-MMMM-yyyy"];
 NSString * created_at = [formatter stringFromDate: date];

output as

enter image description here

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