Winform DataTimePicker控件的时间格式

先设置好dateTimePicker下面两个属性:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss";//HH是24小时,hh是12小时 然后用下面的方法就可以得到时,分,秒的值了:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{ DateTime date = DateTime.Parse(dateTimePicker1.Text);
string hours = date.Hour.ToString();
string minute = date.Minute.ToString();
string second = date.Second.ToString();
}

你可能感兴趣的:(Winform DataTimePicker控件的时间格式)