CFAbsoluteTimeGetCurrent 和 DST

发布于 2024-12-13 12:43:40 字数 462 浏览 6 评论 0原文

我正在开发一款 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

快乐很简单 2024-12-20 12:43:40

你到底是什么意思

([NSDate date] 返回时间的本地化版本,带或不带“AM”、“PM”、“pm”或任何其他变体...例如,如果您的手机设置为阿拉伯语,它会返回阿拉伯字符语言!)。

[NSDate date] 返回一个 NSDate* 对象。我假设您真正的意思是 -[NSDate description] 的输出返回在用户当前区域设置中本地化的字符串,但问题是,为什么您依赖于 的输出>-[NSDate 日期]?如果您需要以某种方式格式化日期,您应该使用 NSDateFormatter

What on earth do you mean by

([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!).

[NSDate date] returns an NSDate* 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.

笑饮青盏花 2024-12-20 12:43:40

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. an NSDate object) you should look at NSDateFormatter, 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文