I got a Issue i am using this code in 'View did Load' and DateText is the UIOutlet of Text Field
[datePicker setDate:[NSDate date]];
[datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventAllTouchEvents];
[self.DateText setInputView:datePicker];
[datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];
and
-(void)updateTextField:(id)sender
{
UIDatePicker *picker = (UIDatePicker*)self.DateText.inputView;
self.DateText.text = [NSString stringWithFormat:@"%@",picker.date];
}
and the Ouptut i am getting in the TextField(DepartureDateText) is
2013-06-13 07:38:22 +0000
Can anyone Suggest me how can i get rid of +0000 and also what Does +0000 indicate.
You should use a NSDateFormatter
to change the NSDate
to the local date time representation:
-(void)updateTextField:(id)sender {
UIDatePicker *picker = (UIDatePicker*)self.DateText.inputView;
self.DateText.text = [NSDateFormatter localizedStringFromDate:picker.date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];;
}
I highly recommend using NSDateFormatter
with the NSDateFormatterStyle
to represent your dates. This will format the date the way the user wants it.
By using dateFormatter you can do anything with your date;
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
myDateFormatter.dateFormat = @"yyyy-MM-dd hh-MM-ss";
NSString *todayString = [myDateFormatter stringFromDate: datePicker.date];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.