关于时间的棘手问题,急!急!急!急!
我要在一个文本框中输入一串数字字符串,当鼠标离开时折断字符串就自动转换成YYYY/MM/DD的格式。
例如:
我输入2001113,当鼠标离开时就自动转换成了2001/01/13
希望各位大侠帮帮我!!!谢了;
[解决办法]
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.TextBox1.Text = "20010113 "
End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
If IsNumeric(Me.TextBox1.Text) And Me.TextBox1.Text.Length = 8 Then
Me.TextBox1.Text = Me.TextBox1.Text.Insert(6, "/ ")
Me.TextBox1.Text = Me.TextBox1.Text.Insert(4, "/ ")
End If
End Sub
End Class
[解决办法]
Dim chrDelimiters() As Char = { "/ "c, "- "c, ". "c}
Dim strSplitDate() As String
strSplitDate = strDate.Split(chrDelimiters)
For i = 0 To strSplitDate.Length - 1
If IsNumeric(strSplitDate(i)) Then
strSplitDate(i) = Format(CLng(strSplitDate(i)), "00 ")
End If
Next
strJoinDate = String.Join( " ", strSplitDate)
Select Case strJoinDate.Length
Case 2
strJoinDate = Format(Now.Date, "yyMM ") & strJoinDate
Case 3
strJoinDate = Format(Now.Date, "yy ") & "0 " & strJoinDate
Case 4
strJoinDate = Format(Now.Date, "yy ") & strJoinDate
Case 5
strJoinDate = Mid(Format(Now.Date, "yy "), 1, 8 - strJoinDate.Length) & strJoinDate
End Select
strRetDate = Mid(strJoinDate, 1, 2) & "/ " & _
Mid(strJoinDate, 3, 2) & "/ " & _
Mid(strJoinDate, 5, 2)
If IsDate(strRetDate) Then
Return strRetDate
Else
Return strDate
End If
[解决办法]
自己逻辑先理理清楚
按照你这种说法还有可能0411就是2004年1月1号的可能性的
你就是再加100分不说清楚需求别人也没办法写的
而且这个东西又不复杂,就是你自己设定的几种输入方式挨个套用