-1

我正在尝试以 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];
4

1 回答 1

0

您有几个不需要的步骤。由于您从日期开始,请执行以下操作:

NSDate *createdDate = [NSDate dateWithTimeIntervalSince1970:[[[sortedEvents objectAtIndex:indexPath.row] objectForKey:@"created_time"] doubleValue]];
[dateFormat setDateFormat:@"MM/dd"];
NSString *condensedString = [dateFormat stringFromDate:longDate];

不需要你做的所有其他来回。

于 2013-11-06T23:10:27.840 回答