我只希望日期不是字符串值的时间。
Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Dim d As String=3/31/2014 12:00:00 AM
Dim str() As String = d.Split("")
End Sub
答案 0 :(得分:2)
使用DateTime.Today属性。它将返回DateTime.Now的日期组件。它等同于DateTime.Now.Date。
DateTime time = DateTime.Now; // Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
Console.WriteLine(time.ToString(format)); // Write to console
答案 1 :(得分:1)
在您的代码稍有变化后,我能够提取日期部分。
Imports System
Public Class Test
Public Shared Sub Main()
Dim d As String= "3/31/2014 12:00:00 AM"
Dim str() As String = d.Split(" ")
Console.WriteLine(str(0))
' 3/31/2014 <----- this is the output
End Sub
End Class
如果您对在数据库中插入日期感到困扰,那么您应该查看数据库的日期函数。例如,SQL Server提供functions to get current date and format it。
答案 2 :(得分:1)
试试这个,
Dim dt as new Date
dt=now()
If CDate(dt) Then
dim str as string=Format(dt,"dd/MM/yyyy")
End If
答案 3 :(得分:0)
尝试这个..
DateTime.Today.ToShortDateString()