如何在 vb.net 中更改 DateTimePicker 的日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5792600/
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
How to change the date format of a DateTimePicker in vb.net
提问by Failed_Noob
How can I change the date format of a DateTimePicker in vb.net so that the date is shown in the format dd/mm/1990, without any time value? I have tried changing the format to "short", and while this provides the date formatting I require it does not remove the time.
如何更改 vb.net 中 DateTimePicker 的日期格式,以便日期以 dd/mm/1990 格式显示,没有任何时间值?我尝试将格式更改为“短”,虽然这提供了我需要的日期格式,但它不会删除时间。
回答by David Hall
You need to set the Format of the DateTimePicker to Custom and then assign the CustomFormat.
您需要将DateTimePicker 的Format 设置为Custom,然后分配CustomFormat。
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = "dd/MM/yyyy"
End Sub
回答by Akram Shahda
Use:
用:
dateTimePicker.Value.ToString("yyyy/MM/dd")
Refer to the following link:
请参考以下链接:
http://www.vbdotnetforums.com/schedule-time/15001-datetimepicker-format.html
http://www.vbdotnetforums.com/schedule-time/15001-datetimepicker-format.html
回答by Govindaram Purushothaman
Try this code it works:
试试这个代码它的工作原理:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CustomeDate As String = ("#" & DOE.Value.Date.ToString("d/MM/yyyy") & "#")
MsgBox(CustomeDate.ToString)
con.Open()
dadap = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM QRY_Tran where FORMAT(qry_tran.doe,'d/mm/yyyy') = " & CustomeDate & "", con)
ds = New System.Data.DataSet
dadap.Fill(ds)
Dgview.DataSource = ds.Tables(0)
con.Close()
Note : if u use dd
for date representation it will return nothing while selecting 1 to 9 so use d
for selection
注意:如果您dd
用于日期表示,则在选择 1 到 9 时将不返回任何内容,因此d
用于选择
'Date time format
'MMM Three-letter month.
'ddd Three-letter day of the week.
'd Day of the month.
'HH Two-digit hours on 24-hour scale.
'mm Two-digit minutes.
'yyyy Four-digit year.
The documentationcontains a full list of the date formats.
该文档包含日期格式的完整列表。