Home  >  Q&A  >  body text

ios - 后台给的时间戳 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];

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

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:39:46

    Send the value of appointmentServiceTime. appointmentServiceTime 的值发一下。

    应该是你[self.appointmentServiceTime integerValue]这个的问题,
    换成doubleValue就都一样了。
    应该是4s上integerValue是int_32,
    而是5s上integerValue是int_64,
    所以你的1457107200000
    It should be your [self.appointmentServiceTime integerValue] problem. If

    is replaced with doubleValue, it will be the same. #🎜🎜# should be that integerValue is int_32 on 4s, #🎜🎜# but integerValue is int_64 on 5s, #🎜🎜# so your 1457107200000< /code>This value is greater than the range of 32-bit int values. #🎜🎜#So there is a problem on 4s. #🎜🎜#

    reply
    0
  • PHPz

    PHPz2017-04-17 17:39:46

    You can just parse it directly into Y-m-d H:i:s and give it to the client

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:39:46

    Please refer here:

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

    Written an extension, which is often used in development

    reply
    0
  • Cancelreply