PHP Convert Time from One Timezone to Another Example

By Hardik Savani May 14, 2024 Category : PHP

Hey Guys,

Now, let's see post of convert time from one timezone to another laravel. let’s discuss about php convert time from one timezone to another. I’m going to show you about php convert datetime from one timezone to another. This example will help you php convert date time to different timezone example.

PHP provide some ready made timezone conversion classes but it a very complected. so we have try to define this function simple way.

You can create a simple class and write one function into the class. then you able to use this function everywhere.

Example:

<?php

$date = new DateTime('2022-05-11 12:00:00', new DateTimeZone('Europe/London'));

echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Europe/Bucharest'));

echo $date->format('Y-m-d H:i:sP') . "\n";

?>

Output:

2022-05-11 12:00:00+01:00

2022-05-11 14:00:00+03:00

I hope it can help you...

Tags :
Shares