我正在尝试以MM / dd格式显示推文的日期,但它返回null。 longDate很好,并以长格式显示正确的日期。
NSDate *createdDate = [NSDate dateWithTimeIntervalSince1970:[[[sortedEvents objectAtIndex:indexPath.row] objectForKey:@"created_time"] doubleValue]];
NSString *dateString = [NSString stringWithFormat:@"%@", createdDate];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate *longDate = [dateFormat dateFromString: dateString];
[dateFormat setDateFormat:@"MM/dd"];
NSString *dateString2 = [NSString stringWithFormat:@"%@", longDate];
NSDate *condensedDate = [dateFormat dateFromString:dateString2];
答案 0 :(得分:0)
您有几个不需要的步骤。由于你从一个日期开始,只需这样做:
NSDate *createdDate = [NSDate dateWithTimeIntervalSince1970:[[[sortedEvents objectAtIndex:indexPath.row] objectForKey:@"created_time"] doubleValue]];
[dateFormat setDateFormat:@"MM/dd"];
NSString *condensedString = [dateFormat stringFromDate:longDate];
你不需要来回做所有其他事情。