Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Function ByteToDateStr(bytDate() As Byte) As String
Dim i As Long
CopyMemory i, bytDate(0), 4
ByteToDateStr = CStr(i \ 10000) & "/" & CStr((i \ 100) Mod 100) & "/" & CStr(i Mod 100)
End Function
Private Sub Form_Load()
Dim s As String, a(3) As Byte
'18 40 32 01 = 2007/4/24
a(0) = &H18
a(1) = &H40
a(2) = &H32
a(3) = &H1
s = ByteToDateStr(a)
Debug.Print s
Private Sub Command1_Click()
Dim s As String
s = "18 40 32 01"
MsgBox fm(s)
s = "BA 3F 32 01"
MsgBox fm(s)
End Sub
Private Function fm(ByVal s As String) As String
Dim temp As String
Dim arr
arr = Split(s, " ")
Dim i As Long
For i = UBound(arr) To 0 Step -1
temp = temp & arr(i)
Next
i = CLng("&H" & temp)
temp = CStr(i)
'这里你用format或其他方法格式化字串也可
fm = Left(temp, 4) + "-" + Mid(temp, 5, 2) + "-" + Right(temp, 2)
End Function