tags:

views:

123

answers:

1

I'm trying to set a UIDatePicker to today's date, but the picker isn't behaving.

The code I'm using is pretty simple:

.h

IBOutlet UIDatePicker *datePicker;

.m

- (IBAction)setForCurrent:(id)sender
{

NSDate *today = [NSDate date];

[datePicker setDate:today animated:YES];

}

When I hit the button that is linked to the setForCurrent action, the picker does shift the Day, Month, Hours, and Minutes to the current time.

The issue is that the AM/PM roller always shifts to PM if the current time is in the AM. What is odd is that I've used NSLog to see what date the picker is seeing (datePicker.date) , and it is the correct date.

When the button is hit a second time, the AM/PM roller shifts to be correct again.

Is there some way to work around this bug?

A: 

Don't know if it helps but I had similar problem. In my case when I set

datePicker.date = [NSDate date]

it showed date behind some hours and it depended on time zone I chose on iPhone. May be it is sdk bug but I fixed it by setting

datePicker.timeZone = [NSTimeZone localTimeZone]

Sergei Zaplitny