php - 使用 PHP 更改 MYSQL 中给定寄存器的时区

标签 php mysql timezone

我们将欧洲/马德里时间的日期作为日期时间存储在我们的 MySQL 表中,在 PHP 中我们称它们为 $h

$h 的格式是 2017-03-03 17:30:00

我想知道是否有一种简单的方法可以将这个时间($h)转换成另一个时区

有点像

$h1=changetimezone ($h, 'Europe/Madrid', 'Europe/Dublin')

其中 h1 是 h-1 小时

此示例的结果为 2017-03-03 16:30:00

谢谢

编辑

我试过了

$h1 = new DateTime($h, new DateTimeZone('Europe/Madrid'));
$h1->setTimeZone(new DateTimeZone('Europe/Dublin'));

但我有更深的

$f=strftime('%e/%m/%y %H:%M', strtotime($h1));

我明白了

 strtotime() expects parameter 1 to be string, object given 

编辑 2:

原始 $h 转储:

string(19) "2017-03-03 17:30:00"

但它在MySQL中存储为datetime

最佳答案

您可以使用 DateTime date_timezone_set ( DateTime $object , DateTimeZone $timezone )

http://php.net/manual/en/datetime.settimezone.php

关于php - 使用 PHP 更改 MYSQL 中给定寄存器的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576899/

相关文章:

mysql - 限制来自另一个表属性的数据

c++ - 获取指定格式的数字时区

php - 使用引用 : foreach ($a as &$v) { . 时 foreach 的奇怪行为 ..}

php pdo 哪里请求对给定值不起作用?

mysql - 左连接,每个左条目只有 1 行

mysql - 在 MySQL 中检索客户端时区的自然时间间隔

java - 如何使用 JPA 和 Hibernate 在 UTC 时区中存储日期/时间和时间戳

php - 编译 PHP 扩展 - 如何摆脱 "putwchar() inconsistent dll linkage"警告

php - Symfony2 : Dynamic Routing Prefix

mysql - 困境: Cascade delete or Join delete