5

I know this might sound a silly question, but I did not find in PHP documentation somewhere were they state loud and clear this one.

I have got a web application.

Users of my web appliations are in Europe, but the server running the web appliation is in US.

How should I set the date.timezone php ini directive???

I suppose to where the server is located so if it's in New York: date.timezone = "America/New_York"

But am I right?

Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
  • 2
    Not a silly question but has been asked before: http://stackoverflow.com/questions/1852223/mysql-keep-server-timezone-or-user-timezone http://stackoverflow.com/questions/1981387/which-is-the-best-timezone-settings-for-php-mysql-site http://stackoverflow.com/questions/346770/dealing-with-timezones-in-php – Pekka Feb 12 '10 at 12:39
  • Setting the timezone to New York simply because the server is there seems to me (sorta) like keeping a watch set at Shanghai time just because it was made there. – GZipp Feb 12 '10 at 12:50
  • @Pekka, thanks! After reading the last one you suggested: http://stackoverflow.com/questions/346770/dealing-with-timezones-in-php I undertstood something. I thought date.timezone could break the application or something between PHP and MySQL if not set properly. But I finally understood it can be set to what I want. So I think to follow the suggestion given in the last link, I set the time.zone to GMT 0 and when need to display dates/times I use client side scripting to convert dates/times. – Marco Demaio Feb 12 '10 at 14:40

3 Answers3

2

I think that it's better to set server's local timezone or UTC and change user timezone in script using http://pl.php.net/manual/en/function.date-default-timezone-set.php You can set timezone to Europe/sth or compute it for each client using GeoIP or JavaScript (it should be possible)

skyman
  • 2,422
  • 17
  • 16
2

According to what I read here around on SO the answers is:

  1. set PHP date.timezone ini directive to "UTC" (i.e. 0)
  2. let PHP print in pages the date time (UTC) as a simple Unix time stamp (a number)
  3. let Javacscript transform the UTC Unix time stamp in client time by simply doing:

    new Date(<?php echo DATE_TIME_SERVER_UTC; ?> * 1000);

Marco Demaio
  • 33,578
  • 33
  • 128
  • 159