init] 返回过去一小时的日期?
当我调用
NSDate *now = [[NSDate alloc] init];
以获取当前日期和时间时,我会检查:
NSLog(@"Date now: %@", now);
输出的日期是过去一小时。
2010-10-08 12:04:38.227 MiniBf[1326:207] 现在:2010-10-08 11:04:38 GMT
我的时区是否在某个地方设置不正确?
谢谢!
迈克尔
When I call
NSDate *now = [[NSDate alloc] init];
in order to get the current date and time, I check it with:
NSLog(@"Date now: %@", now);
the date outputted is one hour in the past.
2010-10-08 12:04:38.227
MiniBf[1326:207] Now: 2010-10-08
11:04:38 GMT
Is my time zone set incorrectly somewhere perhaps?
Thanks!
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经看到在 iOS 4.1 设备上运行的 DatePicker 上有这种行为,而在 iOS 4.0 及更早版本上则不会发生这种情况。我无法确认这实际上是同一个错误。
但我建议您通过在 << 上运行该代码来检查是否与 Apple 已确认的有关日期/夏令时/4.1 的错误有关。 4.1.然后您需要决定是否修复该特定版本/日期,还是等待 SDK 的下一个版本来修复它并且不支持 4.1 设备...
我正在谈论的错误我相信只会在通过时发生夏季期间的日期(2010年:3月28日至10月31日)
I've seen that behavior on the DatePicker running on iOS 4.1 devices while on iOS 4.0 and previous it does not happen. I can't confirm it is actually the same bug.
But I suggest you check whether is related with the acknowledged by Apple bug regarding dates/summer time/4.1 by running that code on < 4.1. Then you will need to decide whether to hack a fix for that particular version/dates or wait for the next release of the SDK to fix it and not support 4.1 devices...
The bug I'm talking about I believe only happens while passing dates within the summer time period (2010: 28th March - 31st October)
使用 NSDateFormatter 本地化日期:
Use NSDateFormatter to localize the date:
使用 NSDate *now = [NSDate 日期];
我正在使用它并给了我完美的结果。
Use NSDate *now = [NSDate date];
I am using it and giving me perfect result.
也许您的 iPhone 模拟器中的时区是错误的。按主页按钮,转到settings.app并更正它;)
Maybe your timezone is wrong in your iPhone simulator. Press the home button, go to settings.app and correct it ;)