Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get server timezone In PHP

Tags:

My client needs a system report his plugin running server details, It means I have to get SERVER timezone. Working with Wordpress. Tried on this, But this not working on every server.

$date = new DateTime(); $date->setTimezone(new DateTimeZone(ini_get('date.timezone'))); 

This gives me a fatal error on some servers, Got any common function to get server timezone?
Any suggestions are greatly appreciated.

like image 377
Disapamok Avatar asked May 25 '16 06:05

Disapamok


2 Answers

Try this:

$date = new DateTime(); $timeZone = $date->getTimezone(); echo $timeZone->getName(); 
like image 133
James Avatar answered Oct 14 '22 07:10

James


Kindly refer following link https://www.w3schools.com/php/func_date_default_timezone_get.asp

    <?php       echo date_default_timezone_get();     ?>  

The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.

like image 31
Kavin D Avatar answered Oct 14 '22 06:10

Kavin D