Country Time
Get the Time from a Country
Section titled “Get the Time from a Country”Returns the current Time in a Country
GET/api/time/country-to-time
https://api.cookie-api.com/api/time/country-to-time
Authentication Learn how to get your API Key and use it in your requests!
URL Parameters | |
---|---|
country | Country name or Country code |
curl --location 'https://api.cookie-api.com/api/time/country-to-time?country=germany' \--header 'Authorization: API_Key'
import requests
url = 'https://api.cookie-api.com/api/time/country-to-time?country=germany'headers = { 'Authorization': 'API_Key'}
response = requests.get(url, headers=headers)print(response.json())
const fetch = require('node-fetch');
const url = 'https://api.cookie-api.com/api/time/country-to-time?country=germany';const headers = { 'Authorization': 'API_Key'};
fetch(url, { method: 'GET', headers}).then(response => response.json()).then(data => console.log(data)).catch(error => console.error('Error:', error));
package main
import ( "fmt" "io/ioutil" "log" "net/http")
func main() { url := "https://api.cookie-api.com/api/time/country-to-time?country=germany" req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatal(err) } req.Header.Set("Authorization", "API_Key")
client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) }
fmt.Println("Response:", string(body))}
const https = require('https');
const options = { hostname: 'api.cookie-api.com', path: '/api/time/country-to-time?country=germany', method: 'GET', headers: { 'Authorization': 'API_Key' }};
const req = https.request(options, res => { let data = ''; res.on('data', chunk => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); });});
req.on('error', error => { console.error(error);});
req.end();
require 'net/http'require 'json'require 'uri'
url = URI.parse('https://api.cookie-api.com/api/time/country-to-time?country=germany')request = Net::HTTP::Get.new(url)request['Authorization'] = 'API_Key'
response = Net::HTTP.start(url.hostname, url.port, use_ssl: true) do |http| http.request(request)end
puts JSON.parse(response.body)
use reqwest::blocking::Client;use reqwest::header::HeaderMap;use serde_json::Value;
fn main() { let url = "https://api.cookie-api.com/api/time/country-to-time?country=germany"; let client = Client::new(); let mut headers = HeaderMap::new(); headers.insert("Authorization", "API_Key".parse().unwrap());
let res = client.get(url) .headers(headers) .send() .unwrap();
let json: Value = res.json().unwrap(); println!("{:#?}", json);}
Responses
{ "country_code": "DE", "country_name": "Germany", "timezones": { "Europe/Berlin": "2024-07-14 20:36:42 CEST+0200", "Europe/Busingen": "2024-07-14 20:36:42 CEST+0200", "GMT": "2024-07-14 18:36:42 GMT+0000", "UTC": "2024-07-14 18:36:42 UTC+0000" }}