Getting UTC Time from Coordinates Using the Timezone API

Ken Bowman 321 Reputation points
2025-05-20T03:12:44.0733333+00:00

I am using the "Route Range" API to create an isochrone for a specific location based on traffic at a certain date and time. The departAt argument requires a UTC formatted time, and I am considering using the "Get Timezone By Coordinates" API to obtain this for a location such as Chicago on May 19, 2025, at 6:15 PM.

Is it feasible to use the "Get Timezone By Coordinates" API to retrieve the UTC time for a specific date and time? It appears that the timeStamp argument necessitates knowing the UTC time in advance, meaning I cannot simply input the Chicago coordinates along with "2025-05-19T18:15:00" to get the UTC equivalent (e.g., "2025-05-19T23:15:00Z").

Any guidance on this would be appreciated.

Thanks,

Ken

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
832 questions
{count} votes

Accepted answer
  1. VSawhney 715 Reputation points Microsoft External Staff Moderator
    2025-05-20T04:57:20.23+00:00

    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:

    1. 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.
    2. 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}")
    

    Reference - https://learn.microsoft.com/en-us/rest/api/maps/timezone/get-timezone-by-coordinates?view=rest-maps-2025-01-01&tabs=HTTP

    Hope this helps!
    Thank you!

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.