Drakes Drakes - 1 year ago 113
Linux Question

How to get the physical server timezone (not from php.ini or IP)?

How can one get the timezone of the physical machine sitting at a location on Earth, not the one reported by php.ini (and certainly not through geoIP)?

EDIT: Or at least the timezone reported by the system, not modified by user scripts, if that's the best we can do.

From php.ini or in scripts we can easily set the default timezone. For example, on my box it's



if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';

if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');

date_default_timezone_set: Asia/Tokyo

date.timezone: Asia/Tokyo

However, the physical server is sitting in Mountain Time in the US. The access logs have the timezone string -0700 in them. Is this impossible?

Solved: Using
we can get system time and the timezone. Thanks @codisfy for the inspiration.

echo shell_exec('date +\'%Z\'');


Answer Source

From comment to answer: You can get the system time using shell_exec(). With which you can run a command as it would run on a shell and return you the output.

So doing something like this can help:

shell_exec('date +\'%Z\'');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download