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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay