IOS how to set date format [duplicate]
This question already has an answer here: Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset? 5 answers I have a string like this NSString *datestr = @"2013-08-06T03:51:54+00:00"; I try to set dateformat as below: NSDateFormatter *dformat = [[NSDateFormatter alloc]init]; [dformat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"]; NSDate *date = [dformat dateFromString:datestr]; But the date will be nil, so, can anyone tell me how to set the dateformat, thx! Try this: NSDateFormatter *dformat = [[NSDateFormatter alloc]init]; [dformat setDateFormat:@"yyyy-MM-dd'T