Convert a 64-bit timestamp to a readable value

In my dataset, I have two timestamps. The first is microseconds from the moment the application was launched - for example, 1400805323. The second is described as a 64-bit time stamp, which, I hope, will indicate the synchronization time using the NTP format with the number of seconds from 1/1/1901.

Example of 64 bit timestamps: 129518309081725000 129518309082059000 129518309082393000 129518309082727000 129518309083060000 129518309083394000 129518309083727000

Is there any matlab / python code that could convert it to a readable format?

Any help is greatly appreciated

Steve

+4
source share
2 answers

Assuming these values ​​were generated today, June 6, 2011, these values ​​look like the number of 100 nanosecond intervals since January 1, 1601. This is how Windows NT stores FILETIME . For more concentrated information on this, read this blog post by Raymond Chen. These articles also show how to convert them to anything else.

+5
source

See edit below for an updated response:
For NTP time, 64 bits are divided into seconds and fractions of a second. The top 32 bits are seconds. The bottom 32 bits are a fraction of a second. You get a share by dividing part of the fraction by 2 ^ 32.

So, the first step, convert to double.

If you like python, it's simple enough, I have not added any restrictions:

def to_seconds(h): return (h>>32) + ((float)(h&0xffffffff))/pow(2,32) >>> to_seconds(129518309081725000) 30155831.26845886 

A time module can hide this float in a readable time format.

 import time time.ctime(to_seconds(ntp_timestamp)) 

You will need to worry about where the timestamp was created. time.ctime suggests that you return by January 1, 1970. Therefore, if your program bases ntp time formats from the moment the program starts, you need to add to seconds to normalize the timestamp for ctime.

 >>> time.ctime(to_seconds(129518309081725000)) 'Tue Dec 15 17:37:11 1970' 

EDIT: PyGuy is right, the original timestamps are not ntp timestamps, they are Windows 64 bit timestamps.

Here is the new to_seconds method for converting a 100ns interval based on 1/1/1601 with an interval of 1970 seconds:

 def to_seconds(h): s=float(h)/1e7 # convert to seconds return s-11644473600 # number of seconds from 1601 to 1970 

And a new conclusion:

 import time time.ctime(to_seconds(129518309081725000)) 'Mon Jun 6 04:48:28 2011' 
+5
source

All Articles