PHP date() function not giving correct time

前端 未结 4 1628
清酒与你
清酒与你 2021-01-25 04:34

I am trying to figure out why php date() is giving me the wrong time, setting the actual time back 2 hours.


4条回答
  •  北恋
    北恋 (楼主)
    2021-01-25 05:11

    You would have to use either date_default_timezone_set() or a datetime object, and the user would have to set their own timezone in an options menu somewhere.

    Otherwise, PHP is a server side language and has no idea what time it is on the user's end.

    You would have to use a client side language, JavaScript. You could either have it just be static and display the current user system time, or if for whatever reason you needed to get their time into PHP, you could use some AJAX like scripting to have JavaScript send their time into a script when the page loads.

提交回复
热议问题