将UNIX时间戳转换为非托管代码中的.NET DateTime ticks(不使用.NET) [英] Convert UNIX timestamp to .NET DateTime ticks in unmanaged code (without using .NET)
问题描述
我需要在Python / C ++中构造.NET DateTime值。
I need to "construct" .NET DateTime values in Python/C++.
如何从UNIX时间戳开始计算DateTime存储的刻度数?
How can I compute the number of ticks stored by DateTime starting from a UNIX timestamp?
一个涉及Win32 API的解决方案调用它是确定的(我相信FILETIME函数可以帮助)。
A solution involving Win32 API calls it's ok (I believe FILETIME functions could help).
推荐答案
这将为您提供自Unix Epoc开始的刻度数(即621,355,968,000,000,000)。
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
这给你每秒钟数(即10,000,000)
This gives you ticks per second (which is 10,000,000)
TimeSpan.TicksPerSecond
只是数学从那里(可能会在闰秒内遇到怪异)。
Just math from there (may run into weirdness around leap seconds).
这篇关于将UNIX时间戳转换为非托管代码中的.NET DateTime ticks(不使用.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!