vb.net 在 datetimepicker 中显示日期和时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20783054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:15:18  来源:igfitidea点击:

Display date and time in datetimepicker

vb.netwinformsdatetimepicker

提问by user1532468

Just a general question because after some research, I cannot seem to find an answer.

只是一个普遍的问题,因为经过一些研究,我似乎找不到答案。

Is it possible to display both the date & timein a datetimepicker?

是否可以date & time在 a 中同时显示datetimepicker

I have a situation where the time must be selected independently from the date.

我有一种情况,必须独立于日期选择时间。

I know that a datetimepickercan display just the time or just the date , but I need to display together .

我知道 adatetimepicker可以只显示时间或只显示日期,但我需要一起显示。

Hope there is an answer to this. Thanks

希望有一个答案。谢谢

回答by Vignesh Kumar A

Yes,Using DateTimePicker we can display both date and time together

是的,使用 DateTimePicker 我们可以同时显示日期和时间

Try like this

像这样尝试

 DateTimePicker1.Format = DateTimePickerFormat.Custom
 DateTimePicker1.CustomFormat = "MM dd yyyy hh mm ss"
 MsgBox(DateTimePicker1.Value)

Or Else you need to set these Property in your DateTimePicker1 as

或者,您需要在 DateTimePicker1 中将这些属性设置为

 Format = Custom
 CustomFormat = "MM dd yyyy hh mm ss"

回答by Al-3sli

Try Using CustomFormat for DateTime:

尝试对 DateTime 使用 CustomFormat:

 DateTimePicker1.CustomFormat = "your Format"

回答by Ajay

Try this :

尝试这个 :

 Private Sub DateTimePickerValueChanged(ByVal obj As Object, _

                                       ByVal ergs As EventArgs)

MessageBox.Show("Datetime :" + DTP.Value.ToString())

For more details see this post : http://www.dotnetheaven.com/article/datetimepicker-control-in-vb.net

有关更多详细信息,请参阅此帖子:http: //www.dotnetheaven.com/article/datetimepicker-control-in-vb.net