I have an ASP.NET web app that I'm displaying event DateTimeOffsets with.
I have a DateTimeOffset from the database, and I can display it, but I want to also display the timezone.
DateTime eventOccurance = getDateTimeFromDB();
Console.out.WriteLine(eventOccurance.ToString());
The output would be
6/11/2015 1:02:03 AM -07:00
What I want is to also add in what timezone it is base on the offset. So for this example the offset of -7 hours indicates that it is Mountain Standard Time.
6/11/2015 1:02:03 AM -07:00 (MST)
I can't find any way to do this. The service supports only the United States (it is emergency services related), so I could write a function that figures what time zone you're in myself, but I'm looking for a better standard way to do it.
I was hoping there was a function in TimeZone
or TimeZoneInfo
that would take as a parameter an offset, and return an appropriate TimeZone, but from what I can tell, that does not exist.
edit
Commenter expressed potential similarity to How to display DateTime with an abbreviated Time Zone?
It is similar to that post, but not identical, because he is using the current time zone, and trying to abbreviate it. I care less about abbreviating, and more about figuring out what time zone a DateTimeOffset is actually in.
edit 2
Thanks Mark. Sorry I couldn't find that on my own. I assure you, I looked.
(...)timezoneoffset of UTC and calculate timezone in C#?
Turns out the problem here is that the offset to TimeZone relationship is a one-to-many relationship, and therefore there is no functionality for what I'm trying to accomplish, other than just writing it myself.