Hello Ken Bowman,
In order to convert a local time in Chicago to UTC format using the "Get Timezone By Coordinates" API. Here’s the scoop:
You’re correct that the departAt
argument requires a UTC formatted time, and it can be tricky since the "Get Timezone By Coordinates" API is meant to retrieve the timezone information, but it doesn't automatically convert a specific local time into UTC for you.
To use the "Get Timezone By Coordinates" API effectively, here’s what you're likely to need to do:
- Get Time Zone Information: First, use the "Get Timezone By Coordinates" API with the coordinates for Chicago (
latitude
,longitude
). This will return the timezone details, including any daylight saving time (DST) information applicable for your target date of May 19, 2025. - Calculate UTC Time: Once you have the timezone details, you can apply the appropriate offset to your local time of "2025-05-19T18:15:00" to convert it into UTC. For example, if Chicago is UTC-5 during standard time or UTC-6 during daylight saving time on that date, you'd adjust the time accordingly.
Here’s a general flow you can consider:
- Step 1: Call the "Get Timezone By Coordinates" API with Chicago's coordinates to get the timezone info.
- Step 2: Check if Day light saving time is in effect on your specified date.
- Step 3: Based on whether Day light saving time is in effect, adjust the local time to UTC.
Sample command
import requests
# Define API endpoint and parameters
latitude = 51.507351 # Example latitude (Dublin, Ireland) (51.507351,-0.12775
longitude = -0.12775 # Example longitude
api_key = "<azure map key>"
url = f"https://atlas.microsoft.com/timezone/byCoordinates/json?api-version=1.0&query={latitude},{longitude}&subscription-key={api_key}"
# Send request
response = requests.get(url)
# Check response status and print result
if response.status_code == 200:
print(response.json()) # Parsed JSON response
else:
print(f"Error: {response.status_code}, {response.text}")
Hope this helps!
Thank you!