init] 返回过去一小时的日期?

发布于 2024-09-27 03:12:45 字数 336 浏览 1 评论 0原文

当我调用

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 技术交流群。

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

发布评论

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

评论(4

烧了回忆取暖 2024-10-04 03:12:45

我已经看到在 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)

动次打次papapa 2024-10-04 03:12:45

使用 NSDateFormatter 本地化日期:

NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]); 

Use NSDateFormatter to localize the date:

NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]); 
谁人与我共长歌 2024-10-04 03:12:45

使用 NSDate *now = [NSDate 日期];

我正在使用它并给了我完美的结果。

Use NSDate *now = [NSDate date];

I am using it and giving me perfect result.

梦晓ヶ微光ヅ倾城 2024-10-04 03:12:45

也许您的 iPhone 模拟器中的时区是错误的。按主页按钮,转到settings.app并更正它;)

Maybe your timezone is wrong in your iPhone simulator. Press the home button, go to settings.app and correct it ;)

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