2

I'm trying to use date_default_timezone_set() in PHP, which accepts a timezone identifier as the only parameter.

How do I get the timezone identifier using only the time offset obtained with javascript, such as:

var visitortime = new Date();
timezone = visitortime.getTimezoneOffset();

So now in PHP, I have for example:

$timezone = -120;

How do I use my $timezone with date_default_timezone_set() at this point?

I was trying to go by this answer, however I'm not sure how to properly set the third parameter for date_default_timezone_set() -- the isdst parameter.

How do I know whether it's 0 or 1, depending on only the value obtained from javascript, in my case -120?

Community
  • 1
  • 1
Frantisek
  • 7,485
  • 15
  • 59
  • 102

1 Answers1

3

You cannot identify the timezone simply by knowing the offset from UTC time, because a timezone definition also contains daylight saving time switch dates.

For example, in America, Nevada and Arizona currently have the same time, and the same offset (-0700) from UTC, but Nevada is in the US/Pacific timezone, and Arizona is in America/Phoenix and has no daylight saving.

Go ask your user about it.

Sven
  • 69,403
  • 10
  • 107
  • 109
  • This answer is correct, but there are some things you can do about it in JavaScript. See [this answer](http://stackoverflow.com/a/16526897/634824). – Matt Johnson-Pint Aug 04 '13 at 16:13