格式化时间
by 伍雪颖
+ (NSString *)formatTime:(NSString *)time { NSDateFormatter*dateFormatter =[[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"]; NSDate *date = [dateFormatter dateFromString:time]; [dateFormatter setDateFormat:@"YYYY/MM/dd"]; NSString *dateSent = [dateFormatter stringFromDate:date]; NSString *dateNow = [dateFormatter stringFromDate:[NSDate date]]; if ([dateSent isEqualToString:dateNow]) { [dateFormatter setDateFormat:@"HH:mm a"]; return [NSString stringWithFormat:@"Today %@",[dateFormatter stringFromDate:date]]; }else { [dateFormatter setDateFormat:@"MM/dd HH:mm a"]; return [dateFormatter stringFromDate:date]; } }
时间: 2024-10-23 07:00:19