有一个用c编写的本机方法,它带有一个类型为time_t的参数。 是否可以将C#uint或ulong用于此参数?
答案 0 :(得分:7)
取决于如何在编译DLL的标准C头文件中定义time_t
。
如果time_t
是64位,则C#等效值为long
。
如果time_t
是32位,那么它有2038年的错误,你应该问谁为无版本的版本编写了DLL。
答案 1 :(得分:7)
我认为我不应该说它们是等效的,但您可以通过以下方式将t_time
转换为DateTime
:
int t= 1070390676; // value of time_t in an ordinary integer
System.DateTime dt= new System.DateTime(1970,1,1).AddSeconds(t);
此示例来自 How can I convert date-time data in time_t to C# DateTime class format?
我还应该说UInt32
也用于t _ time
。检查DateTime to time_t
答案 2 :(得分:2)
根据Wikipedia's article on Time_t,您可以使用integer (Int32 or Int64)
符合Unix和POSIX标准的系统将time_t
实现为整数或实数浮点类型(通常为32位或64位整数),表示自Unix纪元开始以来的秒数:午夜UTC 1970年1月1日(不计算闰秒)。
答案 3 :(得分:0)
巴斯塔多的解决方案对我没有帮助。我遇到了DST的问题,因此需要额外转换为当地时间,或者产生的时间相差一小时。这就是我的工作:
return new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(time_t);