How to get system timezone  in PHP

For Windows:-

Method 1:-

<?php
$date = new DateTime();
$date->setTimezone(new DateTimeZone(ini_get('date.timezone')));
print_r($date);
?>
output:-
DateTime Object ( [date] => 2021-12-30 09:55:34.604110 [timezone_type] => 3 [timezone] => Europe/Berlin )
Method 2:-
 <?php
      echo date_default_timezone_get();
  ?> 
output:-
Europe/Berlin

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post