本文介绍了DateTimePicker日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的datetimepicker格式化为MM / dd / yyyy,但没有时间参数。

我将自定义格式设置为MM / dd / yyyy并将格式设置为自定义属性Explorerdw,但是当它将格式写入datagridview时,它是MM / dd / yyyy hh:mm:ss tt。

我的变量声明如下......可以.TEXT是问题吗?

I am trying to format my datetimepicker to MM/dd/yyyy only with no time of day parameter.
I set the custom format to MM/dd/yyyy and set format to custom in the Properties Explorerdw, but when it writes the format to a datagridview, it's "MM/dd/yyyy hh:mm:ss tt".
I have my variable declared as follows... Could the .TEXT be the issue?

Dim datepicked As Date
datepicked = DateTimePicker1.Text
'add column with datepicked
DataGridView1.Columns.Add(AddCol4)
For Each dgvr As DataGridViewRow In DataGridView1.Rows
    dgvr.Cells("Date").Value = datepicked
Next

推荐答案


Dim datepicked As Date
datepicked = DateTimePicker1.Text

Dim AddCol4 As New DataGridViewTextBoxColumn
AddCol4.DataPropertyName = "Date"
AddCol4.HeaderText = "Date"
AddCol4.Name = "Date"
AddCol4.DefaultCellStyle.Format = "MM/dd/yyyy" 'Adding this

DataGridView1.Columns.Add(AddCol4)
For Each dgvr As DataGridViewRow In DataGridView1.Rows
    dgvr.Cells("Date").Value = datepicked
Next





确实如此。

谢谢你,你是一位绅士和学者:)



And it does.
Thanks, you are a gentleman and a a scholar :)


这篇关于DateTimePicker日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:49
查看更多