let myPicker = UIDatePicker(frame:CGRect(x:10,y:20,width:self.view.frame.size.width,height:200))
myPicker.backgroundColor = UIColor.white
//日期选择区间为中文
myPicker.locale = Locale(identifier:"zh_CN")
myPicker.addTarget(self, action: #selector(dateChanged), for: .valueChanged)
self.view .addSubview(myPicker)
//只有日期
myPicker.datePickerMode = .date
//只有时间
//myPickerView.datePickerMode = .time
//修改字体
myPicker.setValue(UIColor.black, forKey: "textColor")
@objc func dateChanged(datePicker:UIDatePicker){
let formatter = DateFormatter();
formatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
print(formatter.string(from: datePicker.date))
}