Created
April 10, 2018 19:52
-
-
Save chetansatasiya/4c87e711048afb83d4316105c6616bed to your computer and use it in GitHub Desktop.
Convert one timezone to another timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function convert_time_one_timezone_to_other_timezone( $current_timezone = '', $time = '', $convert_to_timezone = 'EST' ) { | |
$utc_date = DateTime::createFromFormat( | |
'G:i', | |
"$time", | |
new DateTimeZone("$current_timezone") | |
); | |
$acst_date = clone $utc_date; // we don't want PHP's default pass object by reference here | |
$acst_date->setTimeZone(new DateTimeZone("$convert_to_timezone")); | |
return $acst_date->format('h:ia T'); | |
} | |
$est_time = convert_time_one_timezone_to_other_timezone("Europe/Stockholm","12:00",'EST'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did some work on this some time, will send you the code