Lee Probert Lee Probert - 1 year ago 121
iOS Question

Get NSDate object from server timestamp string

I have a server timestamp format like so

, how can I convert this to an NSDate object?

Answer Source
NSString *serverTimeString=@"2016-11-21T11:04:02";

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate* date = [dateFormatter dateFromString:serverTimeString];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download