Is there a way to convert the .NET timestamp to unix timestamp using python?
posix_epoch_as_dotnet = 621355968000000000
# convert .NET timestamp to POSIX timestamp
posix_timestamp = (130900894153614080 - posix_epoch_as_dotnet) // 10**7
It is easy to convert between a datetime object that represents time in UTC and the timestamps:
#!/usr/bin/env python
from datetime import datetime, timedelta
dotnet_epoch = datetime(1, 1, 1)
posix_epoch = datetime(1970, 1, 1)
utc_time = dotnet_epoch + timedelta(microseconds=dotnet_timestamp//10)
utc_time = posix_epoch + timedelta(seconds=posix_timestamp)
and back:
posix_timestamp = (utc_time - posix_epoch) // timedelta(seconds=1)
dotnet_timestamp = 10 * (utc_time - dotnet_epoch) // timedelta(microseconds=1)
See totimestamp()
function on how to implement // timedelta()
on older Python versions.