2

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).

Meh
  • 7,016
  • 10
  • 53
  • 76

1 Answers1

2

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).

Roman
  • 19,581
  • 6
  • 68
  • 84
  • TimeSpan.TicksPerMillisecond Field -- The value of this constant is 10 thousand; that is, 10,000. – AMissico May 03 '10 at 22:27
  • TimeSpan.TicksPerSecond Field -- The value of this constant is 10 million; that is, 10,000,000. – AMissico May 03 '10 at 22:28
  • TimeSpan.TicksPerMinute Field -- The value of this constant is 600 million; that is, 600,000,000. – AMissico May 03 '10 at 22:29
  • @amissico: That's great, but Unix time is number of seconds since since 1/1/1970, why would he need higher tick resolution (like TicksPerMillisecond)? – Roman May 03 '10 at 22:46
  • At the time I was looking up this information. I just added it because I was updating my development notes, and figured I would save someone some time down the road. – AMissico May 03 '10 at 22:50
  • thanks! searching for 621355968000000000 yields interesting results – Meh May 04 '10 at 00:03