简体   繁体   English

将带有GMT偏移量的MySQL时间戳转换为本地PHP时间戳

[英]Converting MySQL Timestamp with GMT offset to local PHP timestamp

I have a PHP script that's called by an external vendor. 我有一个由外部供应商调用的PHP脚本。 One of the GET values is a timestamp that is MySQL format, GMT + 0200. Here's an example: 其中一个GET值是MySQL格式的时间戳,GMT + 0200.这是一个例子:

2012-07-16 16:51:22 2012-07-16 16:51:22

I can convert that into the format I'm after using: 我可以将其转换为我使用后的格式:

$converted =  date ("m/d/Y h:i:s A", strtotime ($ts) ); 

However I would also like to convert it to the local time, eg GMT + 10. I'm stumped on this last bit - appreciate if anyone can recommend some options for converting between timezones/GMT offsets as I'm not sure which PHP function to use. 但是我还想将它转换为当地时间,例如GMT + 10.我最后一点感到困惑 - 如果有人可以推荐一些时间区/ GMT偏移之间的转换选项,那我就不知道哪个PHP函数了使用。

Use DateTime, like so: 使用DateTime,如下所示:

$date = new DateTime($ts);
$date->setTimeZone(new DateTimeZone("Europe/Amsterdam");
$converted = date_format($date, 'm/d/Y h:i:s A');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM