$date = new DateTime(); $timezone = $date->getTimezone(); $location = $timezone->getLocation(); echo $location['latitude']; // Returns latitude echo $location['longitude']; // Returns longitude echo $location['country_code']; // Returns country code echo $location['timezone']; // Returns timezone echo $location['timezone_db']; // Returns timezone database
$timezone = new DateTimeZone('America/New_York'); $location = $timezone->getLocation(); echo $location['latitude']; // Returns latitude echo $location['longitude']; // Returns longitude echo $location['country_code']; // Returns country code echo $location['timezone']; // Returns timezone echo $location['timezone_db']; // Returns timezone databaseThis code snippet creates a new DateTimeZone object for the America/New_York timezone and retrieves the location information using the getLocation() method. The latitude, longitude, country code, timezone and timezone database information are displayed on the screen. Package Library: PHP Core Library