Update README.md

This commit is contained in:
Bob Wen 2021-11-03 20:11:08 +08:00
parent c4ebcbe0d2
commit f285d1a55c
1 changed files with 20 additions and 0 deletions

View File

@ -105,6 +105,26 @@ npm install
npm run build
```
## The principle
Website returns the server's current date-time in each response's header, like this:
```
HTTP/2 200
Content-Type: text/html; charset=utf-8
Date: Wed, 03 Nov 2021 11:46:19 GMT
...
```
This `Date: Wed, 03 Nov 2021 11:46:19 GMT` is the moment the website was processing the request, which is in the middle of the time we sent the request and the time we received the response. Simply assuming that the period to send request and receive is equal, we can calculate that the difference between local time and website time:
```js
duration = received_at - sent_at
delta = server_time - received_at - duration / 2
```
There is one more error to consider. Imagine you get a Date value of `23` seconds, which could be `23.000` seconds, or `23.999` seconds. So we having to give 0.500s as compensation for the calculation.
## License
© 2021 Bob Wen