How does one convert a .NET tick to a python datet

2019-01-24 11:31发布

问题:

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?

回答1:

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

For your example, this returns

datetime.datetime(2010, 9, 29, 11, 15)