Php 在用户时区中显示MySQL日期时间
使用Php 在用户时区中显示MySQL日期时间,php,mysql,node.js,timezone,Php,Mysql,Node.js,Timezone,使用now()创建的MySQL日期时间存储为UTC 使用JavaScript检测客户端时区,并返回为“Europe/London” 从MySQL中选择datetime并在用户本地时间中显示创建的时间的最佳方式是什么 PHP和Node都与MySQL一起使用。您可以使用MySQL函数 您可以使用MySQL函数 我不知道您的逻辑是如何生成的,但我在PHP中使用了以下内容: function utc_to_timezone($format, $date, $to_timezone) { $dat
now()
创建的MySQL日期时间存储为UTC
使用JavaScript检测客户端时区,并返回为“Europe/London”
从MySQL中选择datetime并在用户本地时间中显示创建的时间的最佳方式是什么
PHP和Node都与MySQL一起使用。您可以使用MySQL函数
您可以使用MySQL函数
我不知道您的逻辑是如何生成的,但我在PHP中使用了以下内容:
function utc_to_timezone($format, $date, $to_timezone)
{
$date = new DateTime($date);
$date->setTimezone(new DateTimeZone($to_timezone));
return $date->format($format);
}
例如:
echo utc_to_timezone('Y-m-d H:i:s', '2014-07-04 15:34:23', 'Europe/London');
我不知道您的逻辑是如何生成的,但我在PHP中使用了以下内容:
function utc_to_timezone($format, $date, $to_timezone)
{
$date = new DateTime($date);
$date->setTimezone(new DateTimeZone($to_timezone));
return $date->format($format);
}
例如:
echo utc_to_timezone('Y-m-d H:i:s', '2014-07-04 15:34:23', 'Europe/London');