以下是设置datetimepicker值更改时间的代码
private void o_start_ValueChanged(object sender, EventArgs e)
{
o_start.CustomFormat = "dd-MM-yyyy hh:mm:ss";
o_start.Value = Convert.ToDateTime(System.DateTime.Today.ToShortDateString() + " 00:00:00");
}
但在我选择日期后,winforms仍然显示12:00:00,有人知道这是什么问题吗?
更改自定义格式小时部分:
o_start.CustomFormat = "dd-MM-yyyy HH:mm:ss";
注意首都HH
编辑
虽然这不是你的问题,正如@ZoharPeled在他的评论中提到的,你可以使用DateTimePicker
的Today
属性初始化你的System.DateTime
:
o_start.Value = System.DateTime.Today;
对于24小时格式,小时应为HH而不是hh
o_start.CustomFormat = "dd-MM-yyyy HH:mm:ss";