iOS 地址簿(联系人)中新西兰时区的生日
当时区设置为新西兰时,我从地址簿中检索生日日期时遇到了这个奇怪的问题。 当我使用 NSDateFormatter 格式化日期时,它显示错误的日期(总是加上一天)。
因此,我有一个 ABRecordRef 并获取如下所示的生日日期:
NSDate *birthday = objc_unretainedObject(ABRecordCopyValue(record,
kABPersonBirthdayProperty));
现在要获取日期的本地化字符串,我执行以下操作:
NSString *s = [NSDateFormatter localizedStringFromDate:birthday dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterNoStyle];
例如,联系人的生日是 1975 年 10 月 5 日(在地址簿的联系人详细信息中显示如下) ),但上面的代码生成 6/10/1975 总是迟到一天。而且似乎只有当我将时区设置为新西兰时才会发生。我在设备上尝试过,将时区设置为新西兰,甚至在 iPhone 模拟器中将 Mac 的时区设置为新西兰时,都会发生这种情况。
非常感谢任何对此的反馈或帮助,我不确定我是否遇到了 iOS bug 或者我是否做错了什么(例如,在处理地址簿中的日期时,我可能必须使用特定的时区,而不是用户时区?)。
I have this weird issue with birthday dates retrieved from the address book when the timezone is set to new zealand.
When I format the date using a NSDateFormatter it shows the wrong date (always plus one day).
So I have a ABRecordRef and get the birthday date like this:
NSDate *birthday = objc_unretainedObject(ABRecordCopyValue(record,
kABPersonBirthdayProperty));
Now to get a localized string of the date I make this:
NSString *s = [NSDateFormatter localizedStringFromDate:birthday dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterNoStyle];
The birthday of the contact for example is 5 October 1975 (it's displayed like this in the contact details in the address book), but the code above produces 6/10/1975
It's always one day late. And it seems to happen only when I set the timezone to new zealand. I tried it on a device, set timezone to new zealand and this happens, or even in the iPhone simulator when I set the timezone of my mac to New Zealand.
Would greatly appreciate any feedback or help about this, I'm not sure if I ran into an iOS bug or if I'm doing something wrong (for example maybe I have to use a specific timezone when dealing with dates from the addressbook and not the user timezone?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论