1

I have a text field that shows a datepicker once tapped. (I followed these instructions)

Once the text field is tapped the Datepicker appears with the correct date and time. If I changed the day the textfield's date-text shows the correct date from the datepicker, but if I change the hour or minute of the datepicker, the textfield shows one hour delay. I tried using

myDatePicker.timeZone = [NSTimeZone systemTimeZone];

but unfortunately it didn't worked. I could manually* add an hour to it, but I don't really know, if it will be an appropriate solution. I would appreciate if somebody has a better solution to this issue. Thank you very much in advance.

Community
  • 1
  • 1
fernyfine
  • 79
  • 4
  • You already notices its something with the time zone. Remember that if your are using the 'Date' from the datePicker, the value of 'Date' is in UTC. Probably you are in a region with GMT+/-1. – karim Feb 20 '12 at 15:04

1 Answers1

0

I solved the time-problem by formatting the date from the Datepicker.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];

NSString *timeString = [dateFormatter stringFromDate:myDatePicker.date];
timeTextField.text = [NSString stringWithFormat:@"%@",timeString];

[dateFormatter release];
fernyfine
  • 79
  • 4