I am using asp.net mvc and I am using a method that was on this site.
How do I enumerate all time zones in .NET?
So this is what I doing. I then display the results to the user. The user picks their timezone and I saved the display name in the database.
However I am now trying to actually do time zone conversion.
I am trying to do it like this(I am not sure if this is the right way to do it though).
TimeZoneInfo zoneInfo = TimeZoneInfo.FindSystemTimeZoneById(id);
var time = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, zoneInfo);
So I think this would be right it gets the system time and the users time zone and uses this information to convert it to the local UTC time.
So assuming this is all right what I done(if not please correct me) the problem I am facing is how do I get the Id?
I have no clue how to find the id. Like I am willing to save the ID instead of the DisplayName in the database but I have no clue how to figure out the ID from the DisplayName.
Thanks
Perhaps cache them at startup in a dictionary:
Then fetch as
zones[displayName](or viazones.TryGetValue(displayName, out zone)if you want to be safe).