[英]Convert time in PHP from gmt offset
For example i have a time string of "11:00" and and gmt offset string of "+02:00". 例如,我的时间字符串为“ 11:00”,而gmt偏移字符串为“ +02:00”。
How can i combine the two to make the conversion in PHP? 如何将两者结合起来进行PHP转换?
Here is my current code: 这是我当前的代码:
$time = $row->time;
//Get users gmt setting
$timezone = $this->_get_gmt();
//calculate correct time here
$time = ; //whatever i have to do.
All answers appreciated. 所有答案表示赞赏。
$date = DateTime::createFromFormat('H:i P', '11:00 +02:00');
$date->setTimeZone(new DateTimeZone('GMT'));
echo $date->format('H:i');
This: 这个:
You can use a DateTime
object to do that 您可以使用
DateTime
对象执行此操作
$date = new DateTime('Your Time String here');
$date->setTimezone(new DateTimeZone('GMT'));
echo $date->format('Y-m-d H:i:sP') . "\n";
Try: 尝试:
$time = $row->time;
$timezone = $this->_get_gmt();
$time = date( "H:i:s", strtotime( $time )+ $timezone * 60 * 60 )
assuming that $time
is in time format: eg. 假设
$time
为时间格式:例如 14:30, and $timezone
is offset number eg. 14:30,
$timezone
是偏移量,例如。 2. 2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.