加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

从日期/时间vb.net删除时间

发布时间:2020-12-17 00:32:44 所属栏目:大数据 来源:网络整理
导读:Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Form2.Show() Form2.TextBox1.Text = dgv1.CurrentRow.Cells(0).Value.ToString Form2.TextBox2.Text = dgv1.CurrentRow.Cells(1).Value.ToSt
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
    Form2.Show()

    Form2.TextBox1.Text = dgv1.CurrentRow.Cells(0).Value.ToString
    Form2.TextBox2.Text = dgv1.CurrentRow.Cells(1).Value.ToString
    Form2.TextBox3.Text = dgv1.CurrentRow.Cells(2).Value.ToString
    Form2.TextBox4.Text = dgv1.CurrentRow.Cells(3).Value.ToString
    Form2.TextBox5.Text = dgv1.CurrentRow.Cells(4).Value.ToString
    Form2.TextBox6.Text = dgv1.CurrentRow.Cells(5).Value.ToString
    Form2.TextBox7.Text = dgv1.CurrentRow.Cells(6).Value.ToString

textbox5是应该只显示日期的那个,但是当我点击按钮时,文本框会显示日期和时间.例如:12/01/12 12:00 AM.

如何将时间从显示到文本框中删除?

由于CurrentCells(4).Value是一个对象,请尝试将其转换为DateTime,然后使用 ToShortDateString Method进行转换
Form2.TextBox5.Text = CType(dgv1.CurrentRow.Cells(4).Value,DateTime).ToShortDateString

或者您可以使用DateTime.TryParse,如果转换成功,将返回true

Dim tempDate As Date
If DateTime.TryParse(CStr(dgv.CurrentRow.Cells(4).Value),tempDate) Then
    Form2.TextBox5.Text = tempDate.ToShortDateString
Else
    Form2.TextBox5.Text = "Invalid Date"
End If

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读