字节问题
4个字节存放 当前的 月日时分秒
D0-D5:秒
D6-D11:分
D12-D16:时
D17-D21:日
D22-D25:月
请问该怎么凑这四个字节呢?
月日时分秒CC F7 7C 01 ----低字节先发 这四个字节又表示的什么时间呢?怎么转换?
谢谢
[解决办法]
Option Explicit
Private Type DateTime
Month As Integer
Day As Integer
Hour As Integer
Minute As Integer
Second As Integer
End Type
Private Type ByteArray
Data(0 To 3) As Byte
End Type
Private Sub DateTimeToByteArray(A As DateTime, B As ByteArray)
Dim lResult As Long
With A
lResult = .Month And &HF
lResult = lResult * &H10 + .Day And &H1F
lResult = lResult * &H20 + .Hour And &H3F
lResult = lResult * &H40 + .Minute And &H3F
lResult = lResult * &H40 + .Second And &H3F
End With
B.Data(0) = lResult And &H100
B.Data(1) = lResult \ &H100 And &H100
B.Data(2) = lResult \ &H10000 And &H100
B.Data(3) = lResult \ &H1000000 And &H100
End Sub
Private Sub ByteArrayToDateTime(B As ByteArray, A As DateTime)
Dim lResult As Long
lResult = B.Data(0) + B.Data(1) * &H100& + B.Data(2) * &H10000 + B.Data(3) * &H1000000
With A
.Second = lResult And &H3F
lResult = lResult \ &H40
.Minute = lResult And &H3F
lResult = lResult \ &H40
.Hour = lResult And &H3F
lResult = lResult \ &H40
.Day = lResult And &H1F
lResult = lResult \ &H20
.Month = lResult And &HF
End With
End Sub
Private Sub Form_Load()
Dim A As DateTime, B As ByteArray
B.Data(0) = &HCC
B.Data(1) = &HF7
B.Data(2) = &H7C
B.Data(3) = &H1
ByteArrayToDateTime B, A
Debug.Print A.Month, A.Day, A.Hour, A.Minute, A.Second
End
End Sub
[解决办法]
Overall information:
http://forums.devx.com/showthread.php?t=51708