-1

How can I calculate exact difference between a server time and GMT time ? I want to send a POST request to a server on specific time but I know the server time is not accurate so I want to calculate inaccuracy of the server clock (mili seconds) to send my request on time.(if I send request earlier server will block me ) I try this code on ubuntu but it's only show server time.

curl -I --silent www.server.com | grep "^Date"

if I can calculate difference between my pc and server clock it's very helpful for me.

Ferrion X
  • 9
  • 3

1 Answers1

0

There are many options, of course. Here’s a suggestion.

Write a shell script or .bat file that runs your curl and grep commands at feeds the result into a program that you write.

Write the program in Java or another language that runs on the Java Virtual Machine since this probably has the best support for handling date and time, though all the major programming languages can.

In your program you may use DateTimeFormatter.RFC_1123_DATE_TIME for parsing the server time into an OffsetDateTime. Get the PC time as another OffsetDateTime and use Duration.between() for finding the difference (positive or negative).

Beware that there will be a delay from reading the server time until reading the PC time, so results will not be accurate. If you want a better estimate of upper and lower bound somehow read the PC time both before and after reading the server time.

Links

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161