I'm using this :
string url = string.Format("https://maps.googleapis.com/maps/api/timezone/json?location={0},{1}×tamp=1374868635&sensor=false", lat, lon);
using (HttpClient cl = new HttpClient())
{
string json = await cl.GetStringAsync(url).ConfigureAwait(false);
TimeZoneModel timezone = new JavaScriptSerializer().Deserialize<TimeZoneModel>(json);
}
To get user timezone. This works fine. I want to convert this :
"timeZoneName" : "Central European Summer Time"
To .net timezone ?
In .net Timezone that timezone does not exists.
I tried to get proper timezone with :
TimeZoneInfo tzf = TimeZoneInfo.FindSystemTimeZoneById("Central European Summer Time");
Any idea how to convert google timezone to .net timezone ? Is that possible ?
Thank you guys in advance !
Instead of using timeZoneName
, I'd suggest using timeZoneId
, which will be an IANA ID such as Europe/London
.
You then have various options:
TzdbDateTimeZoneSource
, e.g. with TzdbDateTimeZoneSource.WindowsMapping
. See this answer for sample code.DateTimeZone
instead, and use Noda Time throughout your app, for a better date/time experience in generalObviously I favour the last option, but I'm biased as the main author of Noda Time...
See more on this question at Stackoverflow