Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one convert a .NET tick to a python datetime?

I have a file with dates and times listed as huge numbers like 634213557000000000. I believe this is a .NET tick. That's the number of 100 nanosecond increments since midnight on January 1, 1 A.D. What's a good way to read that into a python datetime object?

like image 258
Judge Maygarden Avatar asked Oct 06 '10 18:10

Judge Maygarden


1 Answers

datetime.datetime(1, 1, 1) + datetime.timedelta(microseconds = ticks//10)

For your example, this returns

datetime.datetime(2010, 9, 29, 11, 15)
like image 171
Mark Ransom Avatar answered Oct 04 '22 08:10

Mark Ransom