0
可能重复:
NSDateFormatter not giving me correct的NSDate和NSDateFormatter不一致
我使用的NSDate我使用以下方法转换为只日期:
+ (NSDate *) dateOnly:(NSDate *)date
{
long time = [date timeIntervalSinceReferenceDate];
long timeMod = time % kNumSecondsInDay;
NSTimeInterval newTime = time - timeMod;
return [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:newTime];
}
这给我预期的结果:
NSLog(@"Due Date:%@", _dueDate);
- >截止日期:2012年11月21日00:00:00 +0000
然而,当我使用的日期格式,它给了我一天以前:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSString *result = [formatter stringFromDate:_dueDate];
NSLog(@"Result: %@", result);
- >结果:11/20/12
是什么给出的?
时区是什么给。 (重复约100其他“NSDateFormater不起作用”的线程。) –
我看到了问题,谢谢。 – Destron