Reputation: 32986
I'm using a UIDatePicker in time mode to get the time. I'm trying to display the time selected in a label. The following code doesn't work
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"h:mm a"];
label.text = [outputFormatter stringFromDate:self.datePicker.date];
[outputFormatter release];
Upvotes: 0
Views: 1571
Reputation: 11
It seems you are just trying to set the time format in setDateFormat.
Call the below function as your selector method - Resolved.
- (void)changeDateInLabel:(id)sender{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterMediumStyle];
[df setDateStyle:NSDateFormatterShortStyle];
[df setDateFormat:@"MM/dd/yyyy"];
[df setTimeZone:@"h:mm a"];
}
Upvotes: 1
Reputation: 2707
That code looks fine to me. Did you double check that your label/datepicker are linked up correctly (either through IB or however you created them)? Also, in what way specifically does the code not work?
Upvotes: 1