Browse Source

UTC时间读写简化

tags/v2.2.1
yedajiang44 3 years ago
parent
commit
a11d6ce02f
2 changed files with 2 additions and 20 deletions
  1. +1
    -8
      src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs
  2. +1
    -12
      src/JT809.Protocol/MessagePack/JT809MessagePackWriter.cs

+ 1
- 8
src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs View File

@@ -391,14 +391,7 @@ namespace JT809.Protocol.MessagePack
DateTime d;
try
{
ulong result = 0;
var readOnlySpan = GetReadOnlySpan(8);
for (int i = 0; i < 8; i++)
{
ulong currentData = (ulong)readOnlySpan[i] << (8 * (8 - i - 1));
result += currentData;
}
d = JT809Constants.UTCBaseTime.AddSeconds(result).AddHours(8);
d = JT809Constants.UTCBaseTime.AddSeconds(ReadUInt64()).AddHours(8);
}
catch (Exception)
{


+ 1
- 12
src/JT809.Protocol/MessagePack/JT809MessagePackWriter.cs View File

@@ -229,18 +229,7 @@ namespace JT809.Protocol.MessagePack
span[4] = (byte)(value.Millisecond);
writer.Advance(5);
}
public void WriteUTCDateTime(DateTime value)
{
ulong totalSecends = (ulong)(value.AddHours(-8) - JT809Constants.UTCBaseTime).TotalSeconds;
var span = writer.Free;
//高位在前
for (int i = 7; i >= 0; i--)
{
span[i] = (byte)(totalSecends & 0xFF); //取低8位
totalSecends >>= 8;
}
writer.Advance(8);
}
public void WriteUTCDateTime(DateTime value)=>WriteUInt64((ulong)(value.AddHours(-8) - JT809Constants.UTCBaseTime).TotalSeconds);
/// <summary>
/// YYYYMMDD
/// </summary>


Loading…
Cancel
Save