我有 datetime ( 5/24/2013
) 我想把它们分成 3 个字符串,比如
我需要来自 VB.NET 的代码
String 1 = 5
String 2 = 24
String 3 = 2013
我有 datetime ( 5/24/2013
) 我想把它们分成 3 个字符串,比如
我需要来自 VB.NET 的代码
String 1 = 5
String 2 = 24
String 3 = 2013
使用适当的DateTime
属性:
Dim value As New DateTime(2013, 5, 24)
Dim dayString As String = value.Day.ToString()
Dim monthString As String = value.Month.ToString()
Dim yearString As String = value.Year.ToString()
如果你的日期是一个字符串,你必须先解析它:
Dim dt As DateTime = DateTime.ParseExact("5/24/2013", "d", Nothing)
Dim day As String = dt.Day.ToString()
Dim month As String = dt.Month.ToString()
Dim year As String = dt.Year.ToString()
你可以试试这个方法
dim dbDate1 as Date
dim string1 as string
dim string2 as string
dim string3 as string
dim number1 as integer
dim number2 as integer
dim number3 as integer
' Strings
string1 = dbDate1.Day().ToString()
string2 = dbDate1.Month().ToString()
string3 = dbDate1.Year().ToString()
如果您想要一个数字而不是字符串,只需从行尾删除“.ToString()”
' Numbers
number1 = dbDate1.Day()
number2 = dbDate1.Month()
number3 = dbDate1.Year()
无论您的数据是 DATE 还是 DATETIME 对象,它都应该工作相同