dateWithTimeIntervalSince1970 not returning correct date

僤鯓⒐⒋嵵緔 提交于 2019-11-30 21:40:18

The messageDateString method is returning milliseconds since the epoch, not seconds since the epoch. Look at the value of unixTimeStamp in your debugger pane. It's 1384803782032. That is about 1000 times too large to be a current Unix timestamp.

An NSTimeInterval is measured in seconds, not milliseconds. Try this instead:

-(NSDate *)messageDate {
    NSTimeInterval unixTimeStamp = [[self messageDateString] doubleValue] / 1000.0;
    NSDate *messageDate = [NSDate dateWithTimeIntervalSince1970:unixTimeStamp];
    NSAssert(messageDate, @"messageDate should not be nil");
    return messageDate;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!