开发者

PHP Return Correct Time

开发者 https://www.devze.com 2023-01-29 23:20 出处:网络
For the life of me I can\'t figure out how to return the current time in PHP correctly.First let me show you the setup.

For the life of me I can't figure out how to return the current time in PHP correctly. First let me show you the setup.

Server local time is in CST

I am in PST so there is a 2 hour difference. I also put in the htaccess of my server the following statement:

SetEnv TZ Amercia/Los_Angeles

Ok and my PHP statement to pull the current time is

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

But this code seem to return 8 hours ahead...I can't figure out why?开发者_JS百科? I want it to return my PST time...

Thanks guys!


The time function returns universal time (UTC). If you want the local time, use localtime.


Use this function in your script.

date_default_timezone_set('America/Los_Angeles');

List of supported timezones


Try this in a bootstrap type file...

date_default_timezone_set('Amercia/Los_Angeles');

You also don't need to pass $t to the date() function, by default it will use the current time().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号