NTP Timestamp
NTP timestamp is a 64-bit unsigned fixed-point number with the integer part in the first 32 bits and the fractional part in the last 32 bits. It is in seconds relative to 0h UTC on 1 January 1900
The NTP timescale wraps around every 232 seconds (136 years), so the first rollover will occur in 2036.
To convert second part of NTP to date, you can use normal date calculate such as 60s -> 1 mins, etc...
To convert fractional part of NTP, you need to use NTP fraction * (fraction of seconds) / 2 ^ 32.For example of NTP fraction 1329481807, to convert to microseconds, you perform1329481807 * (10 ^ 6) / 2 ^ 32 = 309544 (roughtly)
Hi
ReplyDeleteThats very helpful. So if you had a NTP timestamp of 129517597601544000 taken today from my PC - how would you convert that into a readable date?
So, using my example, if 129518309 is the integer part then that equals 4.10 years? But that places my timestamp around 1904....
any help greatly appreciated,
Steve
Since the 64-bit timestamps used by NTP consist of a 32-bit seconds part and a 32-bit fractional second part, giving NTP a time scale of 232 seconds (136 years) and a theoretical resolution of 2^-32 seconds (233 picoseconds).
ReplyDeleteI am not sure how you derive 129518309 as your integral part. But I will show the calculation base on your give NTP timestamp 129517597601544000
NTP time = 129517597601544000
64 bits = 111001100001000111001000110011101001100111011011101000000
First get the 32 bit binary to decimal for both integral and fractional part
Integral 32 bits = 0001110011000010001110010001 = 30155665
Fractional 32 bits = 10011101001100111011011101000000 = 2637412160
For integral part, it is already representing seconds since epoch of January 1, 1900
Now, let's concentration of the fractional 10011101001100111011011101000000 = 2637412160
To get 2637412160 to millisecond
2637412160 * (10 ^ 6) / 2 ^ 32
roughly = 614070 ms
So, NTP time = 129517597601544000 is 30155665 seconds and 614070 milliseconds
From integral part, it can convert to days by 30155665 / 60 / 60 / 24 = 349 days
So, your given timestamp should be estimated around 1900 December 16. I believe you can derive the hours and second from here.
Hi,
ReplyDeleteI have time as now 12 august 2013,11 hours,17 minutes,10 seconds and 250 Milliseconds. I know how to convert seconds part,Can you please tell me how to convert 250 milliseconds to NTP fraction part time stamp?
second part is 3585295030.
Please advise
Extract from http://stackoverflow.com/questions/2641954/create-ntp-time-stamp-from-gettimeofday
ReplyDelete"In NTP, if I understand correctly, the fraction portion is represented as a fraction of the total possible values. So it's not a 1-to-1. For example, if I represent one second in 1000 parts, then someone gives me a value of .5 seconds with base 60, I'd have to scale that to my on base 1000. With NTP, the base is the 32 bit representation it's transformed into. So 1 second = 2^32 ntp fraction seconds."
So, 250ms to fraction second is 250 * 2^32 / 10^6
Is it 250*2^32/10^6 or 250*2^32/10^3 ( because 250 is in milliseconds not micro seconds )?
ReplyDeletePlease advise
Instead it should be due to millisecond
ReplyDelete(250 * 1000) * 2^32 / 10^6
Base on RFC 958,
"The low-order fraction bit increments at about 0.2-nanosecond intervals, so a free-running one millisecond clock will be in error only a small fraction of one part per million, or less than a second per year."
In general, that is the conversion to picosecond before representing as 2^-32 seconds resolution
NTP time = 129517597601544000
ReplyDeleteintpart: 30155665
fractpart: 2637412160
intpart(ms):
30155665 x 10^3 = 30155665000 ms
fractpart(ms):
(2637412160 / 2^32) x 10^3 =
614.07037079334259033203125 ms
total(ms): 30155665614 ms
Corresponding date: 16/12/1900 0:34:25