DEV Community

mhsohag11
mhsohag11

Posted on

Answer: PHP Calculating Time Difference in Hours Between Two Timezones

You can get difference in hours between two time zones using timezone offset try below code:

$local_tz = new DateTimeZone('America/Los_Angeles');
$local = new DateTime('now', $local_tz);

//NY is 3 hours ahead, so it is 2am, 02:00
$user_tz = new DateTimeZone('America/New_York');
$user = new DateTime('now', $user_tz);

$local_offset = $local->getOffset() / 3600;
$user_offset

Top comments (0)