Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get right time from Custom UIDatePicker in ios
    text
    copied!<p>Hello I'm Beginner in ios I Have create Custom UIDatePicker View This show right date and time but when we click on done button then this show date right but time is not right ....So how do this ....</p> <pre><code>UIDatePicker *DatePicker; UITexField *DateTime; if ([[UIScreen mainScreen] bounds].size.height &gt;480) { DatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,350,320,50)]; } else { DatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,270,320,50)]; } DatePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleTopMargin; DatePicker.datePickerMode = UIDatePickerModeDateAndTime; DatePicker.date = [NSDate date]; [self.DateTime setInputView:DatePicker]; DatePicker.userInteractionEnabled=YES; [self.view addSubview:DatePicker]; UIDatePicker *picker = (UIDatePicker*)self.DateTime.inputView; self.DateTime.text = [NSString stringWithFormat:@"%@",picker.date]; NSLog(@"date picker is %@",self.DateTime.text); NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss +HHmm"]; [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; NSDate *myDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@",DateTime.text]]; NSLog(@"%@", [dateFormatter stringFromDate:myDate]); NSDateFormatter *anotherDateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setAMSymbol:@"AM"]; [dateFormatter setPMSymbol:@"PM"]; [anotherDateFormatter setDateFormat:@"dd/MM/yyyy hh:mm a"]; NSLog(@"%@", [anotherDateFormatter stringFromDate:myDate]); DateTime.text =[anotherDateFormatter stringFromDate:myDate]; NSLog(@"datetime is %@",DateTime.text); </code></pre> <p>this picker showh right time and date in UI but when we click done button(not mention here)then it show .... <code>DateTime.text=date picker is 2013-07-03 05:22:57 +0000</code> after this format it shows <code>2013-07-03 12:00:57 +0000</code></p> <pre><code>03/07/2013 12:00 AM datetime is 03/07/2013 12:00 AM </code></pre> <p>When we Select any time then this show only above time ....Date is right ...but time is wrong so ....solve this problem</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload