I have the following code to Convert from location to TimeZone name.
public TimeZoneResponse ConvertCityToTimeZoneName(string location)
{
TimeZoneResponse response = new TimeZoneResponse();
var plusName = location.Replace(" ", "+");
var address = "http://maps.google.com/maps/api/geocode/json?address=" + plusName + "&sensor=false";
var result = new System.Net.WebClient().DownloadString(address);
var latLongResult = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result);
if (latLongResult.status == "OK")
{
var timeZoneRespontimeZoneRequest = "https://maps.googleapis.com/maps/api/timezone/json?location=" + latLongResult.results[0].geometry.location.lat + "," + latLongResult.results[0].geometry.location.lng + "×tamp=1362209227&sensor=false";
var timeZoneResponseString = new System.Net.WebClient().DownloadString(timeZoneRespontimeZoneRequest);
var timeZoneResult = JsonConvert.DeserializeObject<TimeZoneResult>(timeZoneResponseString);
if (timeZoneResult.status == "OK")
{
response.TimeZoneName = timeZoneResult.timeZoneName;
response.Success = true;
return response;
}
}
return response;
}
So when I pass in "New York, United States", it returns "Eastern Standard Time"
I then have this second functions that converts a time from one source timezone into this other retrieved timezone above.
var timeInDestTimeZone = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(sourceDate.Date, TimeZoneInfo.Local.Id, destination.TimeZoneName);
Its works well until i ran into this example. When I pass in: Melbourne, Australia into the first function I get back: Australian Eastern Daylight Time
When I pass Australian Eastern Daylight Time into my second function (as the final argument), I get this error back:
The time zone ID 'Australian Eastern Daylight Time' was not found on the local computer
Any suggestions on what i am doing wrong? When i look at the response from second google maps API call these are all of the fields that i get back (using LA as an example):
{
"dstOffset" : 0.0,
"rawOffset" : -28800.0,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
When I pass in Melbourne,I see the TimeZoneId field is set to : ""Australia/Hobart"". Is that the right field to look at for the timezone calculation. Or should I be looking at the other "offset" fields?
Any suggestions would be greatly appreciated.