Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to encode and decode 64-bit format NTP timestamp?

I am trying encode and decode NTP timestamp (64-bit) format mentioned in RFC 5905 Section 6.

Please explain me how to encode and decode 64-bit NTP timestamp with an example.

like image 989
Abhishek Avatar asked Jun 05 '26 16:06

Abhishek


1 Answers

The open source Apache Commons Net project includes a Java implementation that encodes and decodes the NTP packet including the NTP 64-bit timestamp.

The NTP 64-bit timestamp is composed of 32-bits for the seconds field and 32-bits for the fractional seconds. The most significant bit (MSB) of seconds value defines the base date as 7-Feb-2036 if 0 or 1-Jan-1900 if 1.

The TimeStamp class encapsulates the conversion of Java Time (i.e., milliseconds since 1-Jan-1970 Epoch) to/from the NTP 64-bit representation. See TimeStamp.toNtpTime() and TimeStamp.getTime() methods. The encoding/decoding is straightforward to convert to C/C# or another language.

like image 190
CodeMonkey Avatar answered Jun 08 '26 04:06

CodeMonkey