DateTimePicker控件如何获取年月日以及时分秒

时间:2026-02-12 21:52:04

1、在窗体程序中已经添加好一个DateTimePicker控件以及一个预览信息的控件

DateTimePicker控件如何获取年月日以及时分秒

2、双击DateTimePicke 编写

//控制日期或时间的显示格式 12小时制

            this.dateTimePicker.CustomFormat = "yyyy-MM-dd hh-mm-ss";

或者//控制日期或时间的显示格式 24小时制

            this.dateTimePicker.CustomFormat = "yyyy-MM-dd HH-mm-ss";

            //使用自定义格式

            this.dateTimePicker.Format = DateTimePickerFormat.Custom;

            //时间控件的启用

            this.dateTimePicker.ShowUpDown = true; 

小编选择了24小时制

DateTimePicker控件如何获取年月日以及时分秒

3、注意名称一致

DateTimePicker控件如何获取年月日以及时分秒

4、双击button

设置显示时间

messagebox.show(dateTimePicker.value.toLongDatestring()+dateTimePicker.value.toLongTimestring())

5、执行结果

DateTimePicker控件如何获取年月日以及时分秒

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com