iPhone:将 Oracle 时间戳转换为 NSDate 或 Unix 时间戳(例如双精度)
有没有一种好+简单的方法将 Oracle Timestamp 转换为 iPhone 上的 NSDate 对象?我已经要求我的客户给我一个时间戳为 Unix 时间戳的数据库(双倍为 0 = 1970 开始),但这对他们来说似乎是一个问题。谢谢。
注意:您可以轻松地将 Unix 时间戳转换为 NSDate,
[NSDate dateWithTimeIntervalSince1970: timestamp] // timestamp is a "double"
我需要做的是将 Oracle 时间戳转换为双精度,即 Unix 时间戳。剩下的就很容易了。
更多信息:我需要使用以 Oracle 时间戳格式表示日期的 NSString 在 iPhone 上运行 Objective-C 代码。 另一个 StackOverflow 线程 建议使用 NSDateFormatter ,但我不知道要使用什么格式,并且该线程中建议的格式化程序的初始化方法会为我生成警告。
Is there a good+easy way to convert an Oracle Timestamp to an NSDate object on the iPhone? I have asked my customer to give me a DB with timestamps as Unix Timestamp (doubles with 0 = start of 1970) but it seems to be a problem for them. Thanks.
Note: You can easily convert a Unix Timestamp to an NSDate with
[NSDate dateWithTimeIntervalSince1970: timestamp] // timestamp is a "double"
What I need to do is convert the Oracle timestamp to a double, aka Unix Timestamp. The rest is easy.
More info: I need Objective-C code to run on the iPhone using NSStrings that represent dates in Oracle Timestamp format. Another StackOverflow thread suggests using NSDateFormatter, but I don't know what format to use and the initialization method for the formatter suggested in that thread generates a warning for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定是否转换为 NSDate,但您可以轻松地将 Oracle 日期转换为 unix 时间戳。下面的 SQL 片段可以做到这一点:
I'm not sure about the converting to an NSDate, but you can convert an Oracle date to a unix timestamp easily. The following SQL snippet will do it:
看起来我最好的选择是使用以下内容:
我不确定 Oracle 时间戳中有多少差异,因此如果上述方法存在问题,我很想知道。
感谢其他答案。我将保留这个问题以邀请其他方法。
It looks like my best bet is to use the following:
I'm not sure how much variance there is in Oracle timestamps, so if there is a problem with the above approach, I'd love to know.
Thanks for the other answers. I will leave the question open to invite other approaches.
遗憾的是您已经接受了这个答案,但这是最好的方法:
...其中 timestampVal 是表示时间戳值的 NSString 对象。
It's a shame that you accepted that answer already but this is the best way to do it:
...where timestampVal is an NSString object representing a timestamp value.