Answer the question
In order to leave comments, you need to log in
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
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?
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 getTimezoneOffset
that 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::getOffset
we 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 questionAsk a Question
731 491 924 answers to any question