【发布时间】:2014-04-22 21:48:30
【问题描述】:
我在 x 轴上显示日期范围时遇到问题。此范围包含日期作为时间戳值:1398172101、1398176156、1398181026、1398196536 等。下面的代码显示了我如何尝试将日期格式化为人类可读的
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm dd/MM/yy"];
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = [NSDate dateWithTimeIntervalSince1970:0.0];
x.labelFormatter = timeFormatter;
我不确定我是否为timeFormatter.referenceDate 设置了正确的值。我在 stackoverflow 上发现了一个问题,它描述了相同的问题,但正确的答案对我不起作用。它告诉将[NSDate dateWithTimeIntervalSince1970:0.0] 分配给timeFormatter.referenceDate
我做错了什么?谢谢
【问题讨论】:
-
时间戳的零 (0) 点是什么?您已将其设置为 1970 年 1 月 1 日。
-
@EricSkroch 我的每个时间戳值都是使用 [[NSDate date] timeIntervalSince1970] 生成的
-
Core Plot 代码看起来没问题。问题是什么?您是否收到格式错误的标签?偏离正确的日期和时间?
-
日期在标签上的格式很好。问题是日期错误,例如: 03:00 03/01/70 。看年份:2070,时间和日期的其余部分也是错误的
标签: ios objective-c ios7 core-plot