如何在vb.net中更改DateTimePicker的日期格式,以便日期以dd / mm / 1990格式显示,没有任何时间值?我已经尝试将格式更改为“短”,虽然这提供了我要求的日期格式,但不会删除时间。
答案 0 :(得分:15)
您需要将DateTimePicker的格式设置为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
答案 1 :(得分:8)
使用:
dateTimePicker.Value.ToString("yyyy/MM/dd")
请参阅以下链接:
http://www.vbdotnetforums.com/schedule-time/15001-datetimepicker-format.html
答案 2 :(得分:3)
尝试使用此代码:
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()
注意:如果您使用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.
documentation包含完整的日期格式列表。