Return correct PHP time

Over the course of my life, I cannot figure out how to correctly return the current time in PHP. First let me show you the settings.

Server local time is in CST

I am in PST, so the difference is 2 hours. I also added the following statement to my server’s htaccess:

SetEnv TZ Amercia / Los_Angeles

Ok and my php instruction for pulling current time

<?php $t = time(); echo(date("D F d Y H:i:s",$t)); ?>

But this code seems to be back 8 hours ahead ... I can't understand why? I want him to return my time PST ...

Thanks guys!

+3
source share
3 answers

Use this function in a script.

date_default_timezone_set('America/Los_Angeles');

List of supported time zones

+1
source

time (UTC). , localtime.

+3

...

date_default_timezone_set('Amercia/Los_Angeles');

You also do not need to pass $tto the function date(), by default it will use the current one time().

+1
source

Source: https://habr.com/ru/post/1779077/


All Articles