API Access

TimeZoneDB provides simple RESTful interface API and returns structured XML or JSON responses. Our API converts latitude & longitude to time zone data. You also able to retrieve time zone information for a specific zone. You need to register a free API key to start using our services. Please consider to donate if you like our free service.

If you use this API for commercial purposes, please upgrade to premium service for more reliable and stable access.


Parameter Description
key Required. Your unique API key you get after register your account.
zone Required. Zone name of an area. You can refer the name from time zone list.
lat Required if zone not specified. Latitude of a city.
lng Required if zone not specified. Longitude of a city.
time Optional. Unix time. Default value: Current timestamp in Unix.
format Optional. xml or json format for the result. Default value: xml
callback Optional. Use for JavaScript JSON callback.


Field Description
status Status of the API query. Either OK or FAIL.
message Error message if any parameters missing or invalid. Empty if no error.
countryCode ISO 3166 country code of the country.
zoneName The name of the time zone. Refer to time zone list.
abbreviation The abbreviation of time zone.
gmtOffset The time offset in seconds based on UTC time.
dst Whether Daylight Savinig Time (DST) is used. 1=Yes, 0=No
timestamp Current local time in Unix timestamp.


Get result for "Australia/Melbourne" in XML format:

<?xml version="1.0" encoding="UTF-8"?>

Get result using latitude and longitude in XML format:
<?xml version="1.0" encoding="UTF-8"?>

Get result for "America/Toronto" in JSON format:

Time Zone Convertion (PHP)
To convert date/time between difference time zones, you may refer to following codes:
/* Description : Converts date/time from Europe/Paris to Asia/Tokyo
   Source      : http://timezonedb.com
   Date        : 23 December, 2011 */

$date = '25-12-2011 07:52:12'; // Current time in Europe/Paris

// Set system time as UTC

// Get Europe/Paris GMT offset
$source = getGmtOffset('Europe/Paris');

// Get Asia/Tokyo GMT offset
$target = getGmtOffset('Asia/Tokyo');

// Difference
$diff = $target - $source;

// Convert date into Unix time
$unix = strtotime($date);

// Show date/time in Tokyo
echo date('d-m-Y H:i:s', $unix+$diff);

function getGmtOffset($zone){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'http://api.timezonedb.com/?key=YOUR_API_KEY&zone=' . $zone . '&format=json');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$json = curl_exec($ch);
	$data = json_decode($json);
	return (int)$data->gmtOffset;

Accessing TimeZoneDB API using JavaScript
	<title>TimeZoneDB JSON Demo</title>
	<script src="//cdn.timezonedb.com/js/timezonedb.min.js" type="text/javascript"></script>
	<script type="text/javascript">
	function displayZone(lat, lng){
		var tz = new TimeZoneDB;
			key: "YOUR_API_KEY",
			lat: lat,
			lng: lng
		}, function(data){
<button onclick="displayZone('53.7833', '-1.75');">Show Time Zone</button>

Third Party Libraries