If you build it and run first time - all is ok. Then change your timezone to another and run it again (without cleaning targets) - in log you'll see correct date (according to new time zone) but in datePicker you'll see other date (from prev time zone). If you clean targets and rebuild it all is ok.
The workaround for this is to set current timezone to datePicker:
If you build it and run first time - all is ok. Then change your timezone to another and run it again (without cleaning targets) - in log you'll see correct date (according to new time zone) but in datePicker you'll see other date (from prev time zone). If you clean targets and rebuild it all is ok.
The workaround for this is to set current timezone to datePicker:
I also had this problem since building my latest update binaries with the new SDK 4.
Interface Builder doesn't even have a field to set the time zone of the UIDatePicker so it has to be done in ViewDidLoad as suggested.
The documents say that leaving it nil and not setting a value would have the same behaviour as
datePicker.timezone = [NSTimeZone localtimezone];
but it definitely doesn't.
Not very helpful of Apple to change the default behaviour of this commonly used object. There must be a lot of app developers hit by this one and now receiving emails from users of their apps in different time zones complaining about their pickers displaying incorrect values.
Any one else out there had issues?
My HoursTracker apps ran into this with the 2.0 (iOS 4) update. I got probably 500 emails about it from users who were very frustrated, and some 1 star reviews.
Apple rushed a 2.0.1 update that includes setting the timezone (and locale) to the current ones. That works around the problem.
I created a simple sample project that demonstrates the problem and submitted it to Apple as a iOS 4 bug.
Note that this bug only comes up if you use a .xib -- the picker behaves properly if you add it in code.
I'm encountering similar problem on simulator iOS 4.0 (SDK 4 final) without IB and it hasn't to do with timezone change after build (I deleted build, cleaned targets and made rebuild).
birthday=2000-07-16 12:00:00 +0300
now =2010-07-14 19:30:46 +0300
But DatePicker displays 2000-07-15. However on iPad simulator (3.2) and iPhone 3.1.2 it works fine. Seems to be a problem on iOS4. It didn't help to set localTimeZone. Btw - my MacBook and simulator is working with timezone of Ukraine (Kiev). I don't have a device with iOS4 to test it.
I'm encountering similar problem on simulator iOS 4.0 (SDK 4 final) without IB and it hasn't to do with timezone change after build (I deleted build, cleaned targets and made rebuild).
birthday=2000-07-16 12:00:00 +0300
now =2010-07-14 19:30:46 +0300
But DatePicker displays 2000-07-15. However on iPad simulator (3.2) and iPhone 3.1.2 it works fine. Seems to be a problem on iOS4. It didn't help to set localTimeZone. Btw - my MacBook and simulator is working with timezone of Ukraine (Kiev). I don't have a device with iOS4 to test it.
I reproduced it too, but I think it's other type of bug that is connected with mode of picker. If you change date picker mode to UIDatePickerModeDateAndTime it will show correct value
__________________ aTimeLogger - application for tracking your everyday activities
Thanks for starting this thread. I've been challenged by this as well. Since my app is frequently used for tracking time across time zones, this is a big problem for me. In viewWillAppear:
Code:
datePicker.timeZone = [NSTimeZone localTimeZone];
Setting localTime Zone improved the situation, but the problem cropped up again. I played around with a number of things and I get the most consistent results with:
Although Today (as displayed in blue on the picker) is not always correct, the correct date is displayed when the time zone changes. Quitting the app and starting up again (iOS 4) always restores the correct behavior to the datePicker. So this problem is only a problem for me because the app is "freeze dried", the time zone changes, the app is brought to the foreground and the datePicker doesn't update for the new localTimeZone.
Hi All,
whatever my experiences say that the following code is more stable solution of the following problem, it picks your device time zone and even format(12 hrs/24 hrs)
I have same problem about UIDatePicker in iOS SDK 4.2, but it seem just for iPad Simulator 4.2. So the date that I choose in UIDatePicker become one day before. But it become normal if I make "pickerDate.datePickerMode = UIDatePickerModeDateAndTime". My apps just need for "UIDatePickerModeDate". Anyone can help me?