0

I was trying to get the time() on a PHP page (localhost), but it seemed it was returning wrong dates. So I tried:

date_default_timezone_set("America/Chicago");
echo "America/Chicago:".time();
echo "<br>";

date_default_timezone_set("Europe/Helsinki");
echo "Europe/Helsinki:".time();

Which outputs:

America/Chicago:1439981623
Europe/Helsinki:1439981623

How is it that these two values are the same? How can I make sure this particular php-page returns times in my timezone, without changing the php.ini file?

binoculars
  • 2,226
  • 5
  • 33
  • 61

1 Answers1

1

As stated at php.net documentation's first highly voted contribution note by "Timo K":

The function time() returns always timestamp that is timezone independent (=UTC).

That said, you must use DateTime objects and it's methods to deal with multiple timezones.

al'ein
  • 1,711
  • 1
  • 14
  • 21