我有一个Y-m-d H:i:s
UTC格式的日期时间字符串,我想将此字符串转换为Y-m-d H:i:s
GMT + 7格式,例如:
$utcDateTime = '2018-10-02 04:08:17';
$gmtDateTime = $this->convertDateTime($utcDateTime);
echo $gmtDateTime; // 2018-10-02 11:01:02
答案 0 :(得分:5)
您可以尝试一下。这是php timezone。
function convertDateTime($date, $format = 'Y-m-d H:i:s')
{
$tz1 = 'UTC';
$tz2 = 'Antarctica/Davis'; // UTC +7
$d = new DateTime($date, new DateTimeZone($tz1));
$d->setTimeZone(new DateTimeZone($tz2));
return $d->format($format);
}
$utcDateTime = '2018-10-02 04:08:17';
echo convertDateTime($utcDateTime); // 2018-10-02 11:08:17