How to get local time in php?

前端 未结 7 1298
野性不改
野性不改 2021-02-02 03:12

I am trying to get the local time using php. I wrote two different versions, but they both give the wrong time

date_default_timezone_set(\'UTC\');
$now = new Dat         


        
7条回答
  •  感情败类
    2021-02-02 03:51

    You need to use javascript because you want the value of time from the client. PHP is a server-side language that evaluates on the server and sends results to the client. So if you try to pull a date/time using a PHP function, it's going to pull the date from the server, which is not always in the client's timezone.

    You can do this in a javascript function and then reference the value in the display.

    var thisDateTime = new Date();

提交回复
热议问题