Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在用户时区中显示MySQL日期时间_Php_Mysql_Node.js_Timezone - Fatal编程技术网

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');