将日期()更改为中心时间


Change date() to central time

我已经学会了如何使用date('g:i a', time())在我正在进行的聊天中输出时间。它的输出大约是晚上7:54。提示是我在中央时区,现在是我的时间8:54。我尝试使用date('g' + 1 + ':i a', time()),但没有成功。有什么想法吗?

感谢

DateTime()DateTimeZone():一起使用

$date = new DateTime(null, new DateTimeZone(date_default_timezone_get()));
$date->setTimeZone(new DateTimeZone('America/Chicago'));
echo $date->format('g:i a');

我使用date_default_timezone_get()获取当前时区,然后使用DateTime::setTimeZone() 更改它