开发者

My date function in PHP doesn't display the correct time

Here's my PHP c开发者_运维问答ode:

echo date('M j y g:i:A');

This doesn't display correct time. why?


Insert this at the very top of your code:

date_default_timezone_set('Asia/Manila');


fix the time zone in php.ini or in the code itself

Add something like this to your php.ini file date.timezone = "Asia/Manila", that will set the default without having you put in the date_default_timezone_set('Asia/Manila'); on every file that uses time functions


It's most likely echoing the time on the server, which is often GMT. If you're time zone is GMT+5, you may need to add 5 hours to the timestamp.

For 5 hours...

$offset = 5 * 60 * 60;
echo date('M j y g:i:A', time() + $offset);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜