首页 > 后台给的时间戳 4s上显示的是1970.1.14 而5s上是正确时间2016.3.5。

后台给的时间戳 4s上显示的是1970.1.14 而5s上是正确时间2016.3.5。

4s是7.1
5s是9.2
百度找不到答案,感觉是系统问题,下面是代码

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[self.appointmentServiceTime integerValue]/1000];
[formatter setDateFormat:@"YYYY.MM.dd"];
NSString *str = [formatter stringFromDate:confromTimesp];

我又用模拟器测试了一下,发现存在同样的问题,也就是说跟手机型号有关,系统版本无关,请问如何适配?

你直接给解析成Y-m-d H:i:s 给客户端不就行了


你把 appointmentServiceTime 的值发一下。

应该是你[self.appointmentServiceTime integerValue]这个的问题,
换成doubleValue就都一样了。
应该是4s上integerValue是int_32,
而是5s上integerValue是int_64,
所以你的1457107200000这个值是大于32位int值的范围的。
所以4s上有问题。


请参考这里:

http://www.henishuo.com/ios-timestamp-date-converted/

写了一个扩展,在开发中经常这么使用的

【热门文章】
【热门文章】