CFAbsoluteTimeGetCurrent 和 DST
我正在开发一款 iPhone 应用程序,用于将图片上传到网络服务器。这些照片的文件名中有拍摄时间。由于它们可以从世界任何地方获取,因此我必须注意时区和夏令时。我想我可以使用 CFAbsoluteTimeGetCurrent,它不应该被本地化([NSDate date] 返回时间的本地化版本,有或没有“AM”,“PM”,“pm”或任何其他变体......例如它返回阿拉伯字符,如果您的手机设置为阿拉伯语!)。
那么,你能建议我一个函数来将 CFAbsoluteTimeGetCurrent 转换为“类似 MySQL”的日期,例如“2011-11-03 14:12:10”吗?
我的第二个问题是:时区和夏令时怎么样?无论 iPhone 时区如何设置,CFAbsoluteTimeGetCurrent 始终返回 UTC 日期?总是免夏令时吗?
当然,我知道本地 iPhone 日期/时间可能是错误的,但毫秒精度对我的应用程序并不重要:)
提前谢谢您!
I'm developing an app for iPhone that uploads pictures to a webserver. These pictures have the time of when they were taken in the filename. Since they can be taken from anywhere in the World, I have to keep attention to timezones and DST. I thought I can use CFAbsoluteTimeGetCurrent, that shouldn't be localized ([NSDate date] returns the localized version of time, with or without "AM", "PM", "p.m." or any other variant... for example it returns Arabian characters, if your phone is set in arabic language!).
So, can you suggest me a function to convert CFAbsoluteTimeGetCurrent to a "MySQL like" date, something like "2011-11-03 14:12:10"?
My second question is: what about timezones and daylight saving? CFAbsoluteTimeGetCurrent always returns an UTC date, no matter how the iPhone timezone is set? Is it always DST-free?
Of course I know that the local iPhone date/time could be wrong, but milliseconds-precision is not important for my application :)
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你到底是什么意思
[NSDate date]
返回一个NSDate*
对象。我假设您真正的意思是-[NSDate description]
的输出返回在用户当前区域设置中本地化的字符串,但问题是,为什么您依赖于的输出>-[NSDate 日期]
?如果您需要以某种方式格式化日期,您应该使用 NSDateFormatter。What on earth do you mean by
[NSDate date]
returns anNSDate*
object. I'm assuming what you really mean is the output of-[NSDate description]
returns a string localized in the user's current locale, but then the question is, why are you depending on the output of-[NSDate date]
? If you need to format a date a certain way, you should use an NSDateFormatter.CFAbsoluteTime
表示一个时间点,与时区或本地化设置无关。如果您想格式化日期(即NSDate
对象),您应该查看NSDateFormatter
,它可以让您指定输出字符串的确切格式和本地化(如果有) 。 (如果您需要在核心基础级别工作,CFDateFormatter
可以做同样的事情。)CFAbsoluteTime
represents a moment in time, independent of time zones or localization settings. If you want to format a date (i.e. anNSDate
object) you should look atNSDateFormatter
, which lets you specify the exact format and localization (if any) of the output string. (If you need to work at the Core Foundation level,CFDateFormatter
does the same thing.)