how to get the server timezone on a windows server with PHP?
for linux:
$systemTimeZone = system('date +%Z');
*nix system:
$systemTimeZone = popen("date +%Z");
windows:
$systemTimeZone = ???
greez & thx, sky...
EDIT: i know about the php function like:
date_default_timezone_get()
date('T')
\DateTime::timezone
but all of this build-in function from PHP are referenz to the setting in the php.ini. i want to know the real used timezone from the OS.
i have try to use the windows command-line tool
systeminfo
but this is to slow for call and parsing. another command line tool i have testet is:
tzutil /g
this is not the timezone format what i want, in my case i get this:
$:> tzutil /g
W. Europe Standard Time
any other ideas for me ?
What about the built-in function?
http://php.net/manual/en/function.date-default-timezone-get.php
This will tell you the servers timezone abbreviation:
$systemTimeZone = date("T");
echo $systemTimeZone;
E.g. EST, MDT ...
I had just now the same error, and found no better solution then using a selfmade mapping. For windows I used this:
// this array can be filled up with whatever you need
$timezones = array(
'GMT' => 'Europe/London'
, '0' => 'Europe/London'
, '1' => 'Europe/London'
, 'GMT Standard Time' => 'Europe/London'
, '2' => 'Europe/Berlin'
, 'W. Europe Standard Time' => 'Europe/Berlin'
);
// getting the timezone
$timezone = exec('tzutil /g');
// and setting it accordingly
if( array_key_exists($timezone, $timezones)) {
echo("> timezone identified as " . $timezones[$timezone] . "
");
date_default_timezone_set($timezones[$timezone]);
} else {
die("Unknown Timezone: " . $timezone);
}