- PHP

How to get the Timezone in PHP

To get the timezone, use one of these solutions:

Solution 1: use date_default_timezone_get() function.

<?php 

echo date_default_timezone_get();

?>

Solution 2: use DateTime().

<?php 

$date = new DateTime();
echo $date->getTimezone()->getName();

?>

How to get the user timezone in PHP

Unfortunately, this is not possible. However, we can overcome this with JavaScript.

<script>
  document.write(Intl.DateTimeFormat().resolvedOptions().timeZone)
</script>

If you need this data in PHP code, you can use AJAX.