将 date() 更改为中央时间

Change date() to central time

我已经想出如何使用 date('g:i a', time()) 来获取时间来输出我正在进行的聊天。它输出类似 7:54 pm 的内容。问题是我在中央时区,现在是 8:54 我的时间。我尝试使用 date('g' + 1 + ':i a', time()) 但没有用。有什么想法吗?

谢谢

使用DateTime() with 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() to get the current time zone and then change it using DateTime::setTimeZone()