I need to convert PHP timestamps according to the user's computer timezone.
Server's timezone is: UTC +1
To do this, first I use javascript.
<script>
var time_offset = new Date().getTimezoneOffset();
time_offset = Number(time_offset) * 60 + 3600; //here I convert minutes to seconds and add 3600 seconds (1 hour) which is the difference between server's time and UTC.
var d = document.write(time_offset);
</script>
PHP
And here I got lost. Don't know how to use strtotime
because time_offset
can be negative and positive number:
$date_convert = '2022-10-27 12:25:46';
$offset = ob_get_clean();
// echo $offset; outputs negative value -3600
$newdate = date("d/m/Y H:i", strtotime("$date_convert + $offset seconds"));
echo $newdate;
This produces:
01/01/1970 01:00