J
J
JackShcherbakov2018-02-12 19:47:55
PHP
JackShcherbakov, 2018-02-12 19:47:55

In what time zone will the sent time from Moscow be in UTC in New York?

Hello! I do not quite understand what the convenience of UTC is. Do I understand correctly that if we create on a server in Moscow $a = new DateTime(), then the $a variable will contain the time that is now in Moscow, respectively, the client from New York will receive Moscow time? Or will the $a variable contain the time in the client's time zone?
If the $a variable always has the time in the server's time zone, then how can we deliver the correct time to the client?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-02-12
@JackShcherbakov

If the $a variable always has the time in the server's time zone, then how can we deliver the correct time to the client?

But just send the time to the client in UTC and let him translate it into local, taking into account regional settings.

D
DanKud, 2018-02-13
@DanKud

The UTC zone is the standard against which the current user's time zone deviation is calculated. In PHP, you can't directly determine the client's time zone, because the client itself has to be polled. This can be done with a JavaScript function getTimezoneOffsetthat shows deviations in minutes from UTC. You can also try to determine geolocation through PHP. First, we get the user's data by IP using the function geoip_record_by_name, then we determine the time zone through geoip_time_zone_by_country_and_region, and finally, with the help, DateTime::getOffsetwe get the deviation of the client's time zone in seconds. But you should immediately keep in mind that none of the methods will give a 100% guarantee of the reliability of the client's time zone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question