使用date()函数显示特定时区的时间/日期 [英] Display time/date in specific timezone using date() function
本文介绍了使用date()函数显示特定时区的时间/日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用date()函数获取日,月和年.
I use the date() function to get day, month and year.
$year = date(y);
$month = date(m);
$day = date(d);
但是我的托管服务在我所处的另一个地方,因此我需要增加11个小时. 你能告诉我我该怎么做吗? 谢谢
But my hosting is in another place where I am, so I need to add 11 hours. could you tell me how can I do that? thanks
推荐答案
可以
date('Y-m-d', strtotime('+11 hours'));
添加11小时或创建DateTime对象并在需要时更改其时区
to add 11 hours or create a DateTime object and change it's timezone where needed
$datetime = new DateTime; // current time = server time
$otherTZ = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($otherTZ); // calculates with new TZ now
或只需使用以下方式设置适当的时区
or simply set the appropriate timezone with
- date_default_timezone_set -设置脚本中的所有日期/时间函数
- date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
这篇关于使用date()函数显示特定时区的时间/日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文