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.
Try this:
Kindly refer following link
https://www.w3schools.com/php/func_date_default_timezone_get.asp
The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.
this code will help you.
Everything mentioned so far gives you the PHP default timezone, which may be set in php.ini or overridden somewhere in the code. If you are looking for the SERVER timezone, here is the solution:
Check with below code:
get some help from python. you can get server timezone offset with python.
run the python code in php with exec