Convert UNIX timestamp to .NET DateTime ticks in unmanaged code (no use of .NET)

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

How can I calculate the number of ticks stored in a DateTime starting at a UNIX timestamp?

The solution using the Win32 API calls it ok (I believe the FILETIME functions can help).

+2


a source to share


1 answer


This will give you the number of ticks since Unix Epoc started (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 (might bump into weirdness around jump seconds).

+1


a source







All Articles