ios - 将 InternetDateTimeString 转换为 NSDate

标签 ios objective-c nsdate

这是我的代码

[NSDate dateFromInternetDateTimeString:internetTime formatHint:DateFormatHintRFC3339];

在终端中我收到此消息

Could not parse RFC822 date: "1370835005000" Possible invalid format.
Could not parse RFC3339 date: "1370835005000" Possible invalid format.

我必须使用哪种格式才能正确地将互联网数据时间转换为 NSDate 格式?

最佳答案

除以 1000 得到秒,将其转换为 double 并创建日期:

NSDate *date = [NSDate dateWithTimeIntervalSince1970:[internetTime doubleValue]/1000.0];

关于ios - 将 InternetDateTimeString 转换为 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17408873/

相关文章:

ios - itunesconnect 如何一次上传多张图片?

ios - 进度的宽度和高度查看

ios - 使用 drawRect 绘制到我自己的 UIView

objective-c - 带有月份名称的日期 Objective-C

ios - 如何在 swift 3 中获取当前日期?

ios - 从 MySQL 数据库导入 iOS 应用程序中的数据

ios - React Native 数字键盘 returnKeyType 标签 iOS

ios - NSLocalizedString 数组

ios - 如何检测来自另一个类的 touchesBegan、touchesMoved、touchesEnded 事件

nsstring - 从服务器接收损坏的信息