Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone UIDatePicker showing wrong date in Central Timezone

I am at a loss. I have an NSDate that gets passed to a UIDatePicker. When I am set to the Eastern time zone, all is fine.

When I am set to Central, the date picker shows the time as being off by 1 hour.

So, if I turn my NSLogs on, this is what I show:

2010-08-25 18:15:19.317[59299:207] ---- into the picker --->2010-08-25 17:37:51 -0500
2010-08-25 18:15:19.318[59299:207] Local Time Zone America/Chicago
2010-08-25 18:15:19.318[59299:207] 2010-08-25 17:37:51 -0500
2010-08-25 18:15:19.319[59299:207] current locale: en_US

But the UIDatePicker displays "Today 6:37 PM".

If I reset my timezone to Eastern, I get this:

2010-08-25 19:26:11.551[59521:207] ---- into the picker --->2010-08-25 18:37:51 -0400
2010-08-25 19:26:11.552[59521:207] Local Time Zone America/New_York
2010-08-25 19:26:11.552[59521:207] 2010-08-25 18:37:51 -0400
2010-08-25 19:26:11.553[59521:207] current locale: en_US

And the UIDatePicker displays "Today 6:37 PM".

Just wondering if anyone out there has seen this before. It looks like a timezone or daylight savings problem, but I can't seem to track it down.

Any help would be appreciated.

edit: I did some more testing with this and it seems like any timezone causes problems. It is almost like the UIDatePicker only wants to display in Eastern. I don't think I have anything set that would do that.

like image 647
John Avatar asked Aug 25 '10 23:08

John


People also ask

How to fix wrong time&date on iPhone?

Sometimes, iPhone may indicate wrong Time & Date, even if ‘Set Automatically’ option is enabled. In such a case, you will have to Manually Correct the Time, Date and the Time Zone. Go to Settings > General > tap on Date & Time. On the next screen, disable Set Automatically option.

Why is my iPhone showing wrong time when travelling?

If your travelling and find your iPhone Showing Wrong Time, the problem is mostly due to your device not being setup to automatically correct its Time & Date based on your Location.

How do I change the time zone on my iPhone?

For example, you might have iOS 9 or earlier, and your country or region, or government changes the time zone or the observance of daylight saving time. If so, follow these steps: Go to Settings > General > Date & Time. Turn off Set Automatically. Tap Time Zone and enter a city with the time zone that you need.

Why does my device show the wrong date and time?

If your device still shows an incorrect date, time, or time zone, 2 change each setting instead of using Set Automatically. For example, you might have iOS 9 or earlier and your country or region or government changes the time zone or the observance of daylight saving time.


1 Answers

I did some more searching. It sure helps if you use the correct search terms.

Anyhow, I found the answer on the iPhoneDevSDK - http://www.iphonedevsdk.com/forum/iphone-sdk-development/52533-uidatepicker-bug-ios-4-a.html - UIDatePicker bug.

It looks like there might be a UIDatePicker bug.

I added this to my code before I set the picker and it fixed the problem.

datePicker.timeZone = [NSTimeZone localTimeZone];

No more problem (for now).

like image 58
John Avatar answered Sep 19 '22 01:09

John