Hi ,
I have tried many things but no solution.
const string GOOGLE_API = "https://maps.googleapis.com";
const string GOOGLE_TIMEZONE_REQUEST =
"maps/api/timezone/xml";
// Pensacola, FL
const double LATITUDE = 25.7877;
const double LONGITUDE = -80.2241;
static string get_time_zone(double latitude,
double longitude,
DateTime date)
{
RestClient client;
string location;
RestRequest request;
RestResponse response;
TimeSpan time_since_midnight_1970;
double time_stamp;
string time_zone = "In error";
try
{
client = new RestClient(GOOGLE_API);
request = new RestRequest(GOOGLE_TIMEZONE_REQUEST,
Method.GET);
location = String.Format("{0},{1}",
latitude,
longitude);
time_since_midnight_1970 = date.Subtract(
new DateTime(1970, 1, 1, 0, 0, 0));
time_stamp = time_since_midnight_1970.TotalSeconds;
request.AddParameter("location", location);
request.AddParameter("timestamp", time_stamp);
request.AddParameter("sensor", "false");
response = (RestResponse)client.Execute(request);
if (response.StatusDescription.Equals("OK"))
{
response.Headers.ElementAt(8).Name.ToString();
string dtHeaderDate = response.Headers.ElementAt(8).Value.ToString();
XmlNode nodeTimeZone;
XmlDocument xml_document = new XmlDocument();
xml_document.LoadXml(response.Content);
nodeTimeZone = xml_document.SelectSingleNode(
"/TimeZoneResponse/time_zone_name");
if (nodeTimeZone != null)
{
time_zone = nodeTimeZone.InnerText;
double dst_offset = Convert.ToDouble(xml_document.SelectSingleNode("/TimeZoneResponse/dst_offset").InnerText.ToString());
double raw_offset = Convert.ToDouble(xml_document.SelectSingleNode("/TimeZoneResponse/raw_offset").InnerText.ToString());
double dtUserDateTime = time_stamp + dst_offset + raw_offset;
DateTime MyDate = DateTime.FromOADate(dtUserDateTime);
TimeZoneInfo.
TimeZoneInfo timeZoneInfo = System.TimeZoneInfo.FindSystemTimeZoneById(time_zone);
DateTime dataTimeByZoneId = System.TimeZoneInfo.ConvertTime(DateTime.Now, System.TimeZoneInfo.Local, timeZoneInfo);
}
}
}
catch (Exception ex)
{
time_zone = "In error";
}
return (time_zone);
}
}
}
Above is my code, and i am getting invalid time zone error because the Googleapi time zones are different from Windows.