PHP ini date.timezone? Server or client location time zone?

这一生的挚爱 提交于 2019-12-23 12:05:53

问题


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?


回答1:


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)




回答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);




回答3:


http://php.net/manual/en/function.date-default-timezone-set.php and How can I easily convert dates from UTC via PHP?



来源:https://stackoverflow.com/questions/2251780/php-ini-date-timezone-server-or-client-location-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!