Reputation: 1511
For example i have a time string of "11:00" and and gmt offset string of "+02:00".
How can i combine the two to make the conversion in 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.
Upvotes: 0
Views: 988
Reputation: 219834
$date = DateTime::createFromFormat('H:i P', '11:00 +02:00');
$date->setTimeZone(new DateTimeZone('GMT'));
echo $date->format('H:i');
This:
Upvotes: 2
Reputation: 73
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. 14:30, and $timezone
is offset number eg. 2.
Upvotes: 1
Reputation: 31654
You can use a DateTime
object to do that
$date = new DateTime('Your Time String here');
$date->setTimezone(new DateTimeZone('GMT'));
echo $date->format('Y-m-d H:i:sP') . "\n";
Upvotes: 1