C# 中DateTime,Delphi TDateTime

关于加密狗的事件,终于搞定了。

所有原因竟然是因为Delphi的TDateTime的起始时间。 

 

按照api求出的值为 41455

如果按照这个uint 转换成时间,考虑的怎么都不对,Google之,如果要转换Integer为DateTime,一般情况是在某个时间基础上+差值。

有的人说1900.1.1 ,有的人说1970.1.1 这两个值和我所需要的都不对。最后在一篇文章中查到, Delphi TDateTime时间起始为:

1899/12/30 00:00:00  C# DateTime起始时间为:0001/01/01 00:00:00  。  所以如果要加上这个数值,起始值应该从1899.12.30 开始。

public static DateTime UNIXTimeToDateTime(uint unix_time)
    {
        System.DateTime time = System.DateTime.MinValue;
        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1899,12,30));
        time = startTime.AddDays(unix_time);
        return time;
    }
这里说的是Delphi,因为我们的硬狗烧录软件是用Delphi写的。这个差值就该按照1899.12.30计算了。
切记切记。

特别鸣谢e: http://www.dotblogs.com.tw/invercent914/archive/2012/01/17/66313.aspx

  

 
原文地址:https://www.cnblogs.com/googlegis/p/2978713.html