- (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)onclick:(id)sender { NSDate *theDate = self.dataPicker.date; // descriptionWithLocale 方法返回本地时间 // currentLocale 返回当前使用者信息 NSLog(@"the date picked is: %@", [theDate descriptionWithLocale:[NSLocale currentLocale]]); // 设定格式化格式 // dd和DD的区别 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]; }
详见注释:关于dd和DD的区别就是,dd返回当前月份的第几天,而DD返回当年的第几天
时间: 2024-10-13 21:58:13