Convert UNIX timestamp to .NET DateTime ticks in unmanaged code (without using .NET)

折月煮酒 提交于 2019-12-11 01:53:18

问题


I need to "construct" .NET DateTime values in Python/C++.

How can I compute the number of ticks stored by DateTime starting from a UNIX timestamp?

A solution involving Win32 API calls it's ok (I believe FILETIME functions could help).


回答1:


This would give you the number of ticks since that the Unix Epoc starts at (which is 621,355,968,000,000,000)

(new DateTime( 1970,1,1) - DateTime.MinValue).Ticks

This gives you ticks per second (which is 10,000,000)

TimeSpan.TicksPerSecond

Just math from there (may run into weirdness around leap seconds).



来源:https://stackoverflow.com/questions/2761498/convert-unix-timestamp-to-net-datetime-ticks-in-unmanaged-code-without-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!