Effect
Initialization
Uidatepicker *pick = [[Uidatepicker alloc] init];
Property 1. Mode
Pick.datepickermode = Uidatepickermodetime;
Writable properties are available
Uidatepickermodetime, // displays hour, minute, and optionally am/pm designation depending on the locale Setting (e.g. 6 | 53 | PM) uidatepickermodedate, // displays month, day, and year depending on the locale setting (e.g . November | 15 | uidatepickermodedateandtime, // displays date, hour, minute, and optionally am/pm Designation depending on the locale setting (e.g. Wed 15 | 6 | 53 | PM) // displays hour and minute (e.g. 1 |
Monitor 1. Add Listener
[Pick addtarget:self Action: @selector (Settimeok:) forcontrolevents:uicontroleventvaluechanged];
2. Implement monitoring
-(void ) Settimeok: (Uidatepicker *) sender {nsdate *date = sender.date; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; Formatter.dateformat = @ " yyyy-mm-dd HH:mm:ss " ;
NSString *datestr = [Formatter stringfromdate:date];
Self.textField.text = [nsstring stringwithformat:@ " %@ , Datestr];
}
enum { Nsdateformatternostyle = kcfdateformatternostyle, nsdateformattershortstyle = Kcfdateformattershortstyle,//"11/23/37" or "3:30pm" Nsdateformattermediumstyle = Kcfdateformattermediumstyle,//\ "Nov, 1937\" nsdateformatterlongstyle = Kcfdateformatterlongstyle,//\ "November, 1937" or "3:30:32pm\" Nsdateformatterfullstyle = Kcfdateformatterfullstyle//"Tuesday, April, 1952 AD" or "3:30:42pm PST "} Nsdateformatterstyle;