How can I get the current Windows time in a PHP script?
Using time()
doesn't seem to work because it is timezone aware and ignores whether DST is actually turned on or not on the server. E.g., if the timezone is set to "America/Los_Angeles" but DST is unchecked (Windows machine), if today's date is say Sept 1, then the windows time can be 1 PM but the PHP time()
will return 2 PM.
How can I get the server's Windows time? (using PHP 5.2.14).
Reproducing the problem
- Set timezone to "America/Los_Angeles" and uncheck the "Daylight Savings Time" checkbox. Set the date to Sept 1, 2010, at 16:00:00 PM.
- Create a simple PHP script with the following, then run it
echo date_default_timezone_get(), date("H:i:s", time());
The output is America/Los_Angeles 17:00:00. Notice the 1 hour difference due to DST.