【发布时间】:2012-04-11 14:09:42
【问题描述】:
我使用 3rd 方 API。根据其规范如下
byte[] timestamp = new byte[] {185, 253, 177, 161, 51, 1}
表示从 1970 年 1 月 1 日开始的毫秒数 为传输而生成
问题是我不知道如何将它翻译成 DateTime。
我试过了
DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long milliseconds = BitConverter.ToUInt32(timestamp, 0);
var result = Epoch + TimeSpan.FromMilliseconds(milliseconds);
结果是 {2/1/1970 12:00:00 AM},但预计是 2012 年。
【问题讨论】:
-
timestamp是使用小端还是原生端? -
所有数据都使用little-endian字节序。
-
预期的结果真的是2012年吗?我得到
14.11.2011 10:49:16 -
您正在使用 BitConverter.ToUInt32() 这肯定不会有帮助...只会查看字节 [0...3](即 32 位)
-
这个 API 如何处理纪元开始之前的日期?它是否将最后一个字节的 MSB 作为符号位线程化?还是它根本不支持这样的日期?