简体   繁体   English

iPad-夏令时转换

[英]iPad - Daylight Saving Conversion

I'm facing an issue, I have NSString that I want to convert to NSDate, region on my device is set to New York so when daylight saving is active my app misbehaves, 我遇到了一个问题,我有一个要转换为NSDate的NSString,我的设备上的区域设置为纽约,因此当启用夏令时时,我的应用程序行为不正常,

Like eg: 03/08/2015 02:00 - 03/08/2015 02:59 例如: 2015年3月8日02:00-2015年3月8日02:59

Whenever the user selects this date-range the datepicker moves it an hour into the future which it should as daylight saving is active but I want my app to be able to pick/select this date-range because in some other region some other user is using the app at this date-range & doing some transaction so how can I my app to handle daylight saving. 每当用户选择此日期范围时,日期选择器会将其移动到未来一小时,因为夏令时有效,所以我希望我的应用能够选择/选择此日期范围,因为在其他地区,其他用户在此日期范围内使用该应用程序并进行一些交易,因此我该如何处理我的夏令时。

Above scenario happens if user picks the date-range from NSDatePicker or If I try to create that date-range using NSDate & NSDateFormatter. 如果用户从NSDatePicker中选择日期范围,或者如果我尝试使用NSDate和NSDateFormatter创建该日期范围,则会发生上述情况。

Thanks. 谢谢。

You asked about NSDatePicker , but I believe that is for OSX. 您询问了NSDatePicker ,但我相信这是针对OSX的。 The datepicker class in iOS is UIDatePicker . iOS中的datepicker类为UIDatePicker At least, this is how it appears from the documentation. 至少,这就是它在文档中的显示方式。

Both of these classes have a timeZone property, which you can set to any valid NSTimeZone instance. 这两个类都具有timeZone属性,您可以将其设置为任何有效的NSTimeZone实例。 When not set explicitly, the default behavior is to use the local time zone. 如果未明确设置,则默认行为是使用本地时区。

So if you want to pick a time in another time zone, with different DST rules, then just set the time zone accordingly. 因此,如果您想使用其他DST规则在另一个时区中选择时间,则只需相应地设置时区即可。 You might consider using the UTC time zone if you want to be able to accept all values. 如果您希望能够接受所有值,则可以考虑使用UTC时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM