Created
January 5, 2023 16:00
-
-
Save gioiliop7/a7c2af6de6732b034caa66b919efce1e to your computer and use it in GitHub Desktop.
[PHP] Get current date or time of specific 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
// If our server has a timezone out of Greece as an example , we can use this function to get the time of that timezone | |
// Supported timezones https://www.php.net/manual/en/timezones.php | |
// Supported time & date formats https://www.php.net/manual/en/datetime.format.php | |
function GetCityTimeDate($format,$timezone) | |
{ | |
$tz = $timezone; | |
$timestamp = time(); | |
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string | |
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp | |
return $dt->format($format); | |
} | |
//An example of Athens | |
$Athens = GetCityTimeDate("H:i:s",'Europe/Athens'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment