下面的代碼是要把一個時間如2005/1/2轉化為2005年01月02日
雖然可以得到結果但是我覺得我寫的很爛~!
Dim str As String
str = System.DateTime.Now.AddDays(-12).ToShortDateString'///獲得時間200*/**/**
Dim i As Integer
Dim iL As Integer
Dim strTemp As String
For i = 0 To 2
Dim int As Integer
int = InStr(1, str, "/")
If i = 0 Then strTemp = Left(str, int - 1) & "年" If i = 1 Then
If Right(Left(str, 2), 1) = "/" Then
str = "0" & str
strTemp += Left(str, int) & "月"
Else strTemp += Left(str, int - 1) & "月"
End If
End If
If i = 2 Then
If Left(str, 1) = "/" Then
str = Right(str, Len(str) - 1)
If Len(str) = 1 Then str = "0" & str
strTemp += str & "日"
Else
If Len(str) = 1 Then str = "0" & str
strTemp += str & "日"
End If
End If
str = Right(str, Len(str) - int)
Next
謝謝大家~!
雖然可以得到結果但是我覺得我寫的很爛~!
Dim str As String
str = System.DateTime.Now.AddDays(-12).ToShortDateString'///獲得時間200*/**/**
Dim i As Integer
Dim iL As Integer
Dim strTemp As String
For i = 0 To 2
Dim int As Integer
int = InStr(1, str, "/")
If i = 0 Then strTemp = Left(str, int - 1) & "年" If i = 1 Then
If Right(Left(str, 2), 1) = "/" Then
str = "0" & str
strTemp += Left(str, int) & "月"
Else strTemp += Left(str, int - 1) & "月"
End If
End If
If i = 2 Then
If Left(str, 1) = "/" Then
str = Right(str, Len(str) - 1)
If Len(str) = 1 Then str = "0" & str
strTemp += str & "日"
Else
If Len(str) = 1 Then str = "0" & str
strTemp += str & "日"
End If
End If
str = Right(str, Len(str) - int)
Next
謝謝大家~!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货