Z
Z
Zimaell2020-08-13 14:20:42
PHP
Zimaell, 2020-08-13 14:20:42

How to set identical time on server and client?

I make a request to the server and only GMT is sent back from the server

<?php
echo gmdate("Y-m-d H:i:s");
?>

and on the client, I immediately display the time received from the server and the time on the client
string _servetTime = answer;
string _clientTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
serverTime.GetComponent<Text>().text = _servetTime;
clientTime.GetComponent<Text>().text = _clientTime;

the request lasts fractions of seconds (approximately 0.2-0.3 seconds)
the answer is
2020-08-13 11:14:47
2020-08-13 11:14:40

i.e. 7 seconds difference, did a series of tests and the difference was always 6-7 seconds, why is that?
How to synchronize it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2020-08-13
@Zimaell

Enable and configure NTP on a single time source.
If the client's OS is not under your control, then you cannot count on the fact that the clocks on the client and server coincide and must figure out how to live with this for your application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question