数据表短日期格式

时间:2016-02-18 19:46:04

标签: vb.net datetime datatable

我有一个vb.net数据表 用户输入数据,因此不涉及SQL表。

当我存储" 2/1/2016"进入数据表并将其吐出,它显示为" 2/1/2016 12:00:00 AM"

将此格式化为" 2/1/2016"的最佳方法是什么?

Dim table As New DataTable
table.Columns.Add("Date", GetType(DateTime))
table.Rows.Add("2/1/2016")
debug.print (table.rows(0)("Date").tostring)

由于

3 个答案:

答案 0 :(得分:1)

以下是我找到的一种方法:

    Dim table As New DataTable
    table.Columns.Add("Date", GetType(DateTime))
    table.Rows.Add("2/1/2016")
    Debug.Print(CDate(table.Rows(0)("Date").ToString).ToString("d"))

用户Plutonix也建议。这也有效!谢谢先生

Debug.Print(Convert.ToDateTime(table.Rows(0)("Date")).ToShortDateString)

答案 1 :(得分:0)

setTimeout()

答案 2 :(得分:0)

将其转换为“MM / dd / yyyy”

CType(table.Rows(0)("Date").ToString, Date).ToShortDateString
相关问题