PHP Convert Time from One Timezone to Another Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get All Dates Between Two Dates in PHP?
- PHP Remove Element from Array by Value Example
- How to Remove First Element from Array in PHP?
- PHP Curl Request with Username and Password Example
- PHP Create Directory If It Doesn't Exist Example
- PHP Find URL in Text (String) and Make Link Example
- PHP Count Number of Pages in PDF File
- How to Partially Hide Email Address in PHP?
- PHP CURL Post Request with Parameters Example
- PHP - How to Reindex Array Key After Unset Key?
- PHP Ajax Infinite Scroll Pagination Example
- How to Make Read More Link from String in PHP?
- PHP Bootstrap Autocomplete Tokenfield using Ajax Example