Retreive Local time from Bing Maps API

Anonymous
2023-09-29T10:07:43.19+00:00

How do I retreive Localtime , Timezone abbreviation from using Bing Api

The code now retreives json .


  string key = "<SubscriptionKey>";
    string query = "Disneyland, Tokyo";


    Uri geocodetime = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/timezone/?q={0}&key={1}", query, key));

    var response1 = client.GetAsync(geocodetime).Result;

    string json1 = await response1.Content.ReadAsStringAsync();

    // Parse the JSON response to extract the address
    dynamic data2 = Newtonsoft.Json.JsonConvert.DeserializeObject(json1);
 //  string timez = data1.resourceSets[0].resources[0].timeZoneAtLocation[0].timeZone[0].localTime;
    Console.WriteLine(data2);
    Console.ReadLine();

"resourceSets": [
    {
      "estimatedTotal": 1,
      "resources": [
        {
          "__type": "RESTTimeZone:http://schemas.microsoft.com/search/local/ws/rest/v1",
          "timeZoneAtLocation": [
            {
              "placeName": "Tokyo Disneyland, Japan",
              "timeZone": [
                {
                  "genericName": "Tokyo Standard Time",
                  "abbreviation": "JST",
                  "ianaTimeZoneId": "Asia/Tokyo",
                  "windowsTimeZoneId": "Tokyo Standard Time",
                  "utcOffset": "9:00",
                  "convertedTime": {
                    "localTime": "2023-09-29T19:04:01",
                    "utcOffsetWithDst": "9:00",
                    "timeZoneDisplayName": "Tokyo Standard Time",
                    "timeZoneDisplayAbbr": "JST"
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "statusCode": 200,
  "statusDescription": "OK",
  "traceId": "eada20864f2c42beb72680a9ca373d6b|PUS000DE26|0.0.0.1|Ref A: 1D8ED5BD662840668F3D3C3048C64765 Ref B: SEL20EDGE0410 Ref C: 2023-09-29T10:04:01Z"
}
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
606 questions
0 comments No comments
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,951 Reputation points
    2023-09-29T16:00:03.52+00:00

    Hi @Anonymous I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Issue:

    Could not extract the local time and the local time abbreviations from the returned API result set

    Solution:

    Extracting the converted local time from the returned result gave the expected result. Here is the code to extract the data using java script.

    Uri geocodetime = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/timezone/?q={0}&key={1}", query, key));
    
        var response1 = client.GetAsync(geocodetime).Result;
    
        string json1 = await response1.Content.ReadAsStringAsync();
    
        // Parse the JSON response to extract the address
        dynamic data2 = Newtonsoft.Json.JsonConvert.DeserializeObject(json1);
        string timez = data2.resourceSets[0].resources[0].timeZoneAtLocation[0].timeZone[0].convertedTime.localTime;
        Console.WriteLine(timez);
        Console.ReadLine();
    

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    I hope this helps!

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2023-09-29T15:34:05.14+00:00

    Solved

    
        Uri geocodetime = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/timezone/?q={0}&key={1}", query, key));
    
        var response1 = client.GetAsync(geocodetime).Result;
    
        string json1 = await response1.Content.ReadAsStringAsync();
    
        // Parse the JSON response to extract the address
        dynamic data2 = Newtonsoft.Json.JsonConvert.DeserializeObject(json1);
        string timez = data2.resourceSets[0].resources[0].timeZoneAtLocation[0].timeZone[0].convertedTime.localTime;
        Console.WriteLine(timez);
        Console.ReadLine();
    
    
    1 person found this answer helpful.
    0 comments No comments