fbpx

How to Use Timezone API

A diagram illustrating the various components and workflow of a Timezone API.
The EasyAPI Timezone Endpoint provides a powerful, yet simple way to fetch time and geographical information for a specific location. This functionality can be incredibly useful for various business cases:
  • Travel & Logistics: Know the local time for shipping or flights.
  • E-commerce: Display product launch times in local time zones.
  • Remote Teams: Coordinate meetings across different geographical locations.
  • Finance: Monitor currency based on the timezone.

Pre-Requisites

To access the EasyAPI Timezone Endpoint, you will need an API key. If you don’t have an API key yet, please refer to the Getting Started Guide to learn how to obtain one.

Step 1: Make an API Request

In Browser

You can directly access the API via your web browser by navigating to the following URL, replacing YOUR_API_KEY with your actual API key:

				
					https://api.easyapi.io/v1.0/timezone?timezone=Europe/Berlin&api_key=YOUR_API_KEY

				
			

In Python

You can use Python’s requests library to make the API call. Here’s a sample code snippet:

				
					import requests

url = "https://api.easyapi.io/v1.0/timezone"
params = {
    'timezone': 'Europe/Berlin',
    'api_key': 'YOUR_API_KEY'
}

response = requests.get(url, params=params)
data = response.json()

				
			

In PHP

You can use PHP’s cURL to fetch the data:

				
					<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.easyapi.io/v1.0/timezone?timezone=Europe/Berlin&api_key=YOUR_API_KEY",
    CURLOPT_RETURNTRANSFER => true
));

$response = curl_exec($curl);
$data = json_decode($response, true);

curl_close($curl);
?>


				
			

Step 2: Analyze the Response

After making the API call, you’ll receive a JSON response similar to the one presented below:

				
					{
   "class":"timezone_info",
   "properties":{
      "datetime":{
         "date":"08/23/2023",
         "date_time":"08/23/2023 21:50:09",
         "date_time_txt":"Wednesday, August 23, 2023 21:50:09",
         "date_time_wti":"Wed, 23 Aug 2023 21:50:09 +0200",
         "date_time_ymd":"2023-08-23T21:50:09+0200",
         "day":"23",
         "day_abbr":"Wed",
         "day_full":"Wednesday",
         "day_wilz":"23",
         "hour_12_wilz":"09",
         "hour_12_wolz":"9",
         "hour_24_wilz":"21",
         "hour_24_wolz":"21",
         "hour_am_pm":"pm",
         "minutes":"50",
         "month":"08",
         "month_abbr":"Aug",
         "month_days":"23",
         "month_full":"August",
         "month_wilz":"08",
         "seconds":"09",
         "time":"21:50:09",
         "week":"34",
         "year":"2023",
         "year_abbr":"23"
      },
      "timezone":{
         "capital":"Berlin",
         "continent":"EU",
         "country":"Germany",
         "country_code":"DE",
         "currency_alpha_code":"EUR",
         "currency_code":"978",
         "currency_country_minor_unit":"2",
         "currency_country_name":"GERMANY",
         "currency_name":"Euro",
         "ds":"D",
         "edgar":"2M",
         "fifa":"GER",
         "fips":"GM",
         "gaul":"93",
         "geoname_id":"2921044",
         "id":"Europe/Berlin",
         "independent":true,
         "ioc":"GER",
         "iso3166_1_alpha_2":"DE",
         "iso3166_1_alpha_3":"DEU",
         "itu":"D",
         "languages":"de",
         "location":"52.5, 13.366666666666667",
         "marc":"gw",
         "phone_prefix":"49",
         "tld":".de",
         "un_m49_code":"276",
         "wmo":"DL"
      }
   }
}
				
			

Field Descriptions

Datetime Fields
Field NameDescriptionExample Value
dateThe date“08/23/2023”
date_timeComplete date and time“08/23/2023 21:50:09”
date_time_txtDate and time in text format“Wednesday, August 23, 2023 21:50:09”
date_time_wtiDate and time with timezone info“Wed, 23 Aug 2023 21:50:09 +0200”
date_time_ymdISO-8601 formatted date and time“2023-08-23T21:50:09+0200”
dayDay of the month“23”
day_abbrAbbreviated day name“Wed”
day_fullFull day name“Wednesday”
day_wilzDay of the month with leading zero“23”
hour_12_wilz12-hour format of the hour with leading zero“09”
hour_12_wolz12-hour format of the hour without leading zero“9”
hour_24_wilz24-hour format of the hour with leading zero“21”
hour_24_wolz24-hour format of the hour without leading zero“21”
hour_am_pmAM or PM“pm”
minutesMinutes“50”
monthMonth“08”
month_abbrAbbreviated month name“Aug”
month_daysDay of the month“23”
month_fullFull month name“August”
month_wilzMonth with leading zero“08”
secondsSeconds“09”
timeTime in HH:MM:SS format“21:50:09”
weekWeek of the year“34”
yearYear“2023”
year_abbrAbbreviated year“23”
Timezone Fields
Field NameDescriptionExample Value
capitalCapital of the region“Berlin”
continentContinent code“EU”
countryCountry name“Germany”
country_codeCountry ISO code“DE”
currency_alpha_codeCurrency Alpha code“EUR”
currency_codeCurrency ISO code“978”
currency_country_minor_unitCurrency minor unit“2”
currency_country_nameCountry name for currency“GERMANY”
currency_nameCurrency name“Euro”
dsDaylight Saving code“D”
edgarEdgar code“2M”
fifaFIFA code“GER”
fipsFIPS code“GM”
gaulGAUL code“93”
geoname_idGeoname ID“2921044”
idTimezone ID“Europe/Berlin”
independentCountry’s independence statustrue
iocIOC code“GER”
iso3166_1_alpha_2ISO 3166-1 alpha-2 code“DE”
iso3166_1_alpha_3ISO 3166-1 alpha-3 code“DEU”
ituITU code“D”
languagesSpoken languages“de”
locationGeographical coordinates (latitude, longitude)“52.5, 13.366666666666667”
marcMARC code“gw”
phone_prefixPhone prefix“49”
tldTop Level Domain“.de”
un_m49_codeUN M49 code“276”
wmoWMO code“DL”

Step 3: Implement in Your Application

Now that you have successfully fetched and analyzed the time and geographical information, you can use this data in a myriad of ways in your application:

  • Show Local Time: Use the datetime object to display local time to your users.
  • Currency Conversion: Leverage the currency_code to convert prices to the local currency in real-time.
  • Localization: Use the languages and country fields to tailor your application’s language to the user.

Here’s an example message you can display to greet your users based on their local time:

Python implementation
				
					# Python Example
if int(data['properties']['datetime']['hour_24_wilz']) < 12:
    greeting = "Good Morning!"
elif int(data['properties']['datetime']['hour_24_wilz']) < 18:
    greeting = "Good Afternoon!"
else:
    greeting = "Good Evening!"

print(f"{greeting} Welcome to our service!")

				
			
PHP implementation
				
					<?php
// Assuming $data is the decoded JSON response
$hour = intval($data['properties']['datetime']['hour_24_wilz']);

if ($hour < 12) {
    $greeting = "Good Morning!";
} elseif ($hour < 18) {
    $greeting = "Good Afternoon!";
} else {
    $greeting = "Good Evening!";
}

echo "$greeting Welcome to our service!";
?>

				
			

Conclusion

Congratulations! You’ve successfully learned how to use EasyAPI’s Timezone Endpoint to retrieve and implement local time data in your application. The flexibility of this endpoint can be immensely useful for various business use-cases, from personalizing greetings to conducting location-based analytics.

What's Next?

  • Getting Started: If you’re new to EasyAPI or need a refresher on how to get started, be sure to check out our Getting Started Guide.

  • More Endpoints: Interested in more functionalities? Take a look at our guide for the IP Address Lookup Endpoint, which is similar to this one but tailored for obtaining IP address information.

  • For Developers: For a deep dive into all available endpoints, parameters, and functionalities, visit our comprehensive API documentation in redoc.

Your journey with EasyAPI is just getting started. We have a range of features and endpoints to meet your needs, and our documentation is always here to help you find your way. Feel free to reach out with any questions or suggestions; we’re always keen to hear your feedback.

Happy coding!

Choose the Plan That Fits Your Need

Easy, transparent, and budget-friendly!

Starter

$3/month

Commercial

$37/month

Premium

$59/month

Business

$139/month