时间选择器选中的时间默认类型为:Time = “2/11/2022 12:00:00 AM”
public void Fun(string date){
//从WPF组件或者组件绑定的对象属性中获取到Time值,本例为绑定了对象student
var birthday = Student.Birthday;
try {
Time = Convert.ToDateTime(StringToDatetime(birthday)).ToString("yyyy-MM-dd HH:mm:ss");
} catch (Exception e){
SystemService.MsgBoxService.ShowMsgBox(e.Message);
return;
}
}
//时间格式转换
public DateTime StringToDatetime(string date) {
return date == string.Empty ? Convert.ToDateTime("0001/1/1") : Convert.ToDateTime(date);
}
转换后的Time格式即为"yyyy-MM-dd HH:mm:ss"格式