The compare API enables you to compare an IP address, an address or a time zone with the purpose of returning differences between two time zones.
Data
Please URL encode all parameter values.
NOTICE.
Below is an example of comparing a time zone with an IP address.
Several compare methods are available.
Please navigate to Methods to view them all.
Returns timezone and datetime information. Date/time defaults to when the request was made.
$ curl https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN
// Get JSON object
$jsondata = file_get_contents("https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN");
// Decode
$data = json_decode($jsondata, true);
// Request OK?
if($data['meta']['code'] == '200'){
// Example: Time difference
echo "Offset: " . $data['data']['compared']['time_difference_hours'] . "<br>";
}
// Require
const request = require('request');
// Request
request('https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN', function(err, res, dat){
// Parse
var data = JSON.parse(dat);
// Request OK?
if(data.meta.code == '200'){
// Log
console.log(data);
// Example: Time difference
var offset = data.data.compared.time_difference_hours;
}
});
// Get JSON object
$.getJSON('https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN', function(data){
// Request OK?
if(data.meta.code == '200'){
// Log
console.log(data);
// Example: Time difference
var offset = data.data.compared.time_difference_hours;
alert(offset);
}
});
# Require
require 'json'
require 'open-uri'
# Get JSON and parse
data = JSON.parse(open('https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN').read)
# If OK, get values
if data['meta']['code'] = 200
offset = data['data']['compared']['time_difference_hours']
puts offset
end
# Import
import requests
# Get
response = requests.get('https://timezoneapi.io/api/compare/timezone-with-ip/?timezone1=Europe/Copenhagen&ip1=66.220.144.0&token=TOKEN')
# Parse JSON
data = response.json()
# If ok, get values
if data['meta']['code'] = 200:
Offset = data['data']['compared']['time_difference_hours']
print Offset
Returns
{ "meta": { "code": "200" }, "data": { "timezone1": { "timezone": { "id": "Europe\/Copenhagen", "location": "55.66666,12.58333", "country_code": "DK", "country_name": "Denmark", "iso3166_1_alpha_2": "DK", "iso3166_1_alpha_3": "DNK", "un_m49_code": "208", "itu": "DNK", "marc": "dk", "wmo": "DN", "ds": "DK", "phone_prefix": "45", "fifa": "DEN", "fips": "DA", "gual": "69", "ioc": "DEN", "currency_alpha_code": "DKK", "currency_country_name": "DENMARK", "currency_minor_unit": "2", "currency_name": "Danish Krone", "currency_code": "208", "independent": "Yes", "capital": "Copenhagen", "continent": "EU", "tld": ".dk", "languages": "da-DK,en,fo,de-DK", "geoname_id": "2623032", "edgar": "G7" }, "datetime": { "date": "12\/12\/2024", "date_time": "12\/12\/2024 12:27:51", "date_time_txt": "Monday, December 12, 2024 12:27:51", "date_time_wti": "Mon, 12 Dec 2024 12:27:51 +0100", "date_time_ymd": "2024-12-12T12:27:51+01:00", "time": "12:27:51", "month": "12", "month_wilz": "12", "month_abbr": "Dec", "month_full": "December", "month_days": "31", "day": "12", "day_wilz": "12", "day_abbr": "Mon", "day_full": "Monday", "year": "2024", "year_abbr": "16", "hour_12_wolz": "12", "hour_12_wilz": "12", "hour_24_wolz": "12", "hour_24_wilz": "12", "hour_am_pm": "pm", "minutes": "27", "seconds": "51", "week": "50", "offset_seconds": "3600", "offset_minutes": "60", "offset_hours": "1", "offset_gmt": "+01:00", "offset_tzid": "Europe\/Copenhagen", "offset_tzab": "CET", "offset_tzfull": "Central European Time", "dst": "false", "dst_observes": "true", "timeday_spe": "late_morning", "timeday_gen": "morning" } }, "ip1": { "ip": "66.220.144.0", "city": "Menlo Park", "postal": "94025", "state": "California", "state_code": "CA", "country": "United States", "country_code": "US", "location": "37.459,-122.1781", "timezone": { "id": "America\/Los_Angeles", "location": "34.05222,-118.24278", "country_code": "US", "country_name": "United States of America", "iso3166_1_alpha_2": "US", "iso3166_1_alpha_3": "USA", "un_m49_code": "840", "itu": "USA", "marc": "xxu", "wmo": "US", "ds": "USA", "phone_prefix": "1", "fifa": "USA", "fips": "US", "gual": "259", "ioc": "USA", "currency_alpha_code": "USD", "currency_country_name": "UNITED STATES", "currency_minor_unit": "2", "currency_name": "US Dollar", "currency_code": "840", "independent": "Yes", "capital": "Washington", "continent": "NA", "tld": ".us", "languages": "en-US,es-US,haw,fr", "geoname_id": "6252001", "edgar": "" }, "datetime": { "date": "12\/12\/2024", "date_time": "12\/12\/2024 03:27:52", "date_time_txt": "Monday, December 12, 2024 03:27:52", "date_time_wti": "Mon, 12 Dec 2024 03:27:52 -0800", "date_time_ymd": "2024-12-12T03:27:52-08:00", "time": "03:27:52", "month": "12", "month_wilz": "12", "month_abbr": "Dec", "month_full": "December", "month_days": "31", "day": "12", "day_wilz": "12", "day_abbr": "Mon", "day_full": "Monday", "year": "2024", "year_abbr": "16", "hour_12_wolz": "3", "hour_12_wilz": "03", "hour_24_wolz": "3", "hour_24_wilz": "03", "hour_am_pm": "am", "minutes": "27", "seconds": "52", "week": "50", "offset_seconds": "-28800", "offset_minutes": "-480", "offset_hours": "-8", "offset_gmt": "-08:00", "offset_tzid": "America\/Los_Angeles", "offset_tzab": "PST", "tz_string": "PST8PDT,M3.3.0/2,M11.2.0/2", "dst": "false", "dst_observes": "true", "timeday_spe": "late_night", "timeday_gen": "night" } }, "compared": { "time_difference_seconds": 32400, "time_difference_minutes": 540, "time_difference_hours": 9 } } }
We've made it easy for you to test out our API's. Simply click the "Token" link on each API page and a temporary token is generated instantly. You can generate up to five test tokens. Each token is valid for 20 requests. When you're ready to put the code into production then sign up for a plan to get a service token.
Service Token (for testing)
A test token has been generated for you. It's good for 20 requests. Please notice: When using a test token the request reponse time is reduced drastically.