更新时间:2023-01-30 17:13:42
您为日期格式使用了错误的格式,也无需创建NSDateFormatter的另一个实例-
You are using wrong format for date format and also there is no need to create another instance of NSDateFormatter -
NSString *inputString=@"15 February 2012 17:05";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd MMMM yyyy HH:mm"];
NSDate *dateVal = [dateFormat dateFromString:inputString];
[dateFormat setDateFormat:@"MM/dd/yyyy HH:mm"];
NSString *outputString = [dateFormat stringFromDate:dateVal];