On iOS, the time and date Selection control is like this. On the left side is the combination of time and date, and on the right side is the pure date mode.
,
You can select four modes as needed: Time, Date, Date and Time, and Count Down Timer.
This article briefly introduces the use of the PickerDate Control
1. Create a Singe View Application named DatePickDemo. Other settings
2. place controls
Open ViewController. xib, drag a DatePicker control to the interface, drag a Button control to the interface, double-click the Button, and enter "select Date and Time"
3. Establish an association between xib and ViewController
Press command + alt + enter to open the Assistant Editor, select DatePicker, press and hold the Control key, and drag it to viewController. h,
Create an Outlet datePicker.
Create an Action Association ing for the Button in the same way and name it selectDate. The event type is the default Touch Up Inside.
4. Implementation Code
Click ViewController. m and find
-(IBAction) selectDate :( id) sender {
}
Add response code here
-(IBAction) selectDate :( id) sender {NSDate * select = [datePicker date]; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @ "yyyy-MM-dd HH: mm"]; NSString * dateAndTime = [dateFormatter stringFromDate: select]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "time prompt" message: dateAndTime delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil]; [alert show];}
Running results:
5. modify the code in Date mode.
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
Example code: https://github.com/schelling/YcDemo
Copyright Disclaimer: This article will be published at http://blog.csdn.net/totogo2010/, and you will be welcomed to enjoy the transfer and sharing. Please respect the work of the author. Keep this note and the author's blog link when reprinting. Thank you.