NSDate *date = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss:SSS"]; NSString *DateTime = [formatter stringFromDate:date]; NSLog(@"时间测试b%@",DateTime);