If you don’t have a problem using a api you can do the following.
// check if user IP exists
if (!empty($_SERVER['REMOTE_ADDR'])) {
// get user data based on IP (not always correct)
$user_ip_data = file_get_contents('http://ipinfo.io/' . $_SERVER['REMOTE_ADDR'] . '/json');
// check if is json object
if (!empty($user_ip_data) && $user_ip_data[0] === '{' && substr($user_ip_data, -1) === '}') {
// create php object from json
$user_ip_data = json_decode($user_ip_data);
// check if timezone exists
if (!empty($user_ip_data->timezone)) {
// create new date time object based on the user timezone
$date = new DateTime('now', new DateTimeZone($user_ip_data->timezone));
// output the time
echo $date->format('d/m/Y H:i:s');
}
}
}
I provided comments for each line of code so you could better understand what each of them does.
Tested it using a vpn to check if timezone changes, and it does.