DateTimePicker 控件,如何设置时间? [英] DateTimePicker control, how to set time?

查看:65
本文介绍了DateTimePicker 控件,如何设置时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我已经更改了显示格式 = 时间的 DateTimePicker 控件中设置时间

How to set time in a DateTimePicker control where i have already changed the display format = Time

我想让 DateTimePicker 显示我设置的时间.

I want to make the DateTimePicker to display time that i set.

例如将其设置为下午 5:30

e.g. set it to 5:30 PM

我尝试使用但失败:

DateTimePicker1.Value = New DateTime(0, 0, 0, 5, 30, 0) 'fail at runtime

任何想法,谢谢

推荐答案

尝试将新 DateTime 的日期部分设置为当前日期:

Try setting the date portion of the new DateTime to the current date:

DateTimePicker1.Value = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 30, 0 )

然后,当您想要读取该值时,只需获取 DateTime 的时间部分.日期部分必须设置为某个值,但由于您只显示时间,因此它是什么并不重要.

Then, when you want to read the value just take the time portion of the DateTime. The date portion has to be set to some value but since you are only displaying the time it doesn't really matter what it is.

这篇关于DateTimePicker 控件,如何设置时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆