OS4 的时间选择器问题?

发布于 2024-09-26 02:12:48 字数 740 浏览 1 评论 0原文

我有一个应用程序,正在更新到 OS4。在此我使用时间选择器。由此我想获得一个小时和分钟作为整数。这是我之前使用的代码...

NSDate *selected = [timePicker date];

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit |NSSecondCalendarUnit;


NSDateComponents *compsDur = [gregorian components:unitFlags fromDate:selected];
int hDur = [compsDur hour];
int mDur = [compsDur minute];
int sDur = [compsDur second];

[gregorian release];

现在这里一切正常。我的问题是,当我更新到 OS4 时,如果我更改手机时间设置(例如从英国更改为美国),我会得到一个随机值,而不是用户输入的值。

举个具体的例子,在英国时间,我将时间设置为 1 分钟,我得到的 mDur 的返回值为 1。如果我然后将手机更改为纽约时间,我会得到 19 小时 6 分钟?这是怎么回事?

I have an app which I am updating to OS4. In this I use a time picker. From this I want to get an hour and minute as an integar. This is the code I used previously for this...

NSDate *selected = [timePicker date];

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit |NSSecondCalendarUnit;


NSDateComponents *compsDur = [gregorian components:unitFlags fromDate:selected];
int hDur = [compsDur hour];
int mDur = [compsDur minute];
int sDur = [compsDur second];

[gregorian release];

Now all was working fine here. My problem is that when I update to OS4 if I change my phones time settings say from the UK to the US I get a random value not what the user has entered.

To give you a specific example, on UK time I set the time for 1 minute, I get a return value for mDur as 1. If I then change my phone to New York time I get 19 hours and 6 minutes? What's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

晨曦慕雪 2024-10-03 02:12:48

我认为这可能与 iOS4 中 UIDatePicker 的未记录更改有关,其中它默认为(我认为是)GMT 作为时区。

您可以将 UIDatePicker 的时区设置为系统时区,以便用户获得预期的体验。

yourDatePicker.timeZone = [NSTimeZone systemTimeZone];

I think this might be related to an undocumented change to the UIDatePicker in iOS4 where it defaults to (what I think is) GMT as the time zone.

You can set the time zone of the UIDatePicker to the system time zone so the user gets the expected experience.

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