开发者

How do I get a date in UK local time using PHP?

I'm using the unix timestamp to show when a开发者_开发百科 message was posted in my project but when I came to displaying the exact time of the post I realized it was about 12 hours behind.

I'm in the UK and my server is in the US (might be the problem).

Is there a simple way of converting the unix timestamp into a readable British time?

$timestamp = time();
print date("F jS, Y", strtotime($timestamp));

Any help would be great, Thanks!


At the top of your script, write:

date_default_timezone_set('Europe/London');

Or if your PHP is >= 5.2.0:

date_timezone_set('Europe/London');


Just call date_timezone_set with the appropriate parameter for the UK at the start of your script when displaying the dates (not when recording them; I 'm not sure, but it might result in the "wrong" timestamps being recorded).

Edit: The timezone you want is 'Europe/London'.


try date-default-timezone-set.

date_default_timezone_set('Europe/London');


Use date_default_timezone_set('Europe/London'); to set the time zone to London's time. Not sure if it works with summer/winter time.


the simplies way is to substruct gmt offset. e.g:

echo(date('Y-m-d h:i'), $myvalue - 60 * 60 * $nhours));

where $nhours - time defference in hours.


This one worked for me

date_default_timezone_set('Europe/London');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜