我们将欧洲/马德里时间的日期作为日期时间存储在我们的 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 )
关于php - 使用 PHP 更改 MYSQL 中给定寄存器的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576899/