Answer the question
In order to leave comments, you need to log in
PHP How to output time zone GMT - or +?
Welcome all.
Knowing the time zone, well, for example, in this format: "America/Los_Angeles", how to display data like "GMT-10" in a variable, and you need to know exactly the zone - or +.
I fight for a long time, I do not know what to apply.
Is there a method? Or does it require complex manipulations?
Thank you in advance.
Answer the question
In order to leave comments, you need to log in
echo date('O'); // +0300
echo date('P'); // +03:00
Solution:
1)
$dtz = new DateTimeZone('America/Los_Angeles');
$zona = new DateTime('now', $dtz);
$offset = $dtz->getOffset($zona) / 3600;
echo "GMT" . ($offset < 0 ? $offset : "+".$offset);
$target_time_zone = new DateTimeZone('America/Los_Angeles');
$date_time = new DateTime('now', $target_time_zone);
echo 'GMT '.$date_time->format('P');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question