Tin*_*cer 0 php timezone datetime date-formatting
我有Y-m-d H:i:sUTC格式的日期时间字符串,我想将此字符串转换为Y-m-d H:i:sGMT + 7格式,例如:
$utcDateTime = '2018-10-02 04:08:17';
$gmtDateTime = $this->convertDateTime($utcDateTime);
echo $gmtDateTime; // 2018-10-02 11:01:02
Run Code Online (Sandbox Code Playgroud)
你可以试试这个.这是php 时区.
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
Run Code Online (Sandbox Code Playgroud)