#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIDatePicker *myDP;
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)clicked:(id)sender {
NSDate *theDate=self.myDP.date;
NSLog(@"the date picked is :%@",[theDate descriptionWithLocale:[NSLocale currentLocale]]);
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSLog(@"the date formate is:%@",[dateFormatter stringFromDate:theDate]);
self.label.text=[dateFormatter stringFromDate:theDate];
}
日期-时间选择器
最新推荐文章于 2024-09-25 23:00:42 发布