Is there any delivered method which takes in timezoneoffset of UTC and calculate timezone in C#?

StackOverflow https://stackoverflow.com/questions/22159386

  •  19-10-2022
  •  | 
  •  

Question

I am calling a service which standardizes a given address and also gives timezone of the result in UTC offset (ex: -5:00 etc).

Is there a function in C# which takes in timezoneoffset of UTC and calculate timezone(Three characters such as CST, EST, PST) ?

Was it helpful?

Solution

No. That's an impossible request in any language, because:

  1. Many different time zones share the same offset.

  2. There is no standard for time zone abbreviations. There is a lot of overlap and ambiguity. For example, "CST" has at least 5 different meanings that I am aware of.

  3. Even if you limit yourself to the United States, you cannot reliably distinguish between offsets. For example, -5 could be EST or it could be CDT.

    There is even one hour a year where EST and CDT are BOTH in effect at the exact same time. For example, this occurred on November 2, 2014, when 1:00 AM EST and 1:00 AM CDT were both in effect simultaneously, and both used the UTC-5 offset.

I am calling a service which standardizes a given address and also gives timezone of the result in UTC offset (ex: -5:00 etc).

Unless the service is returning the offset for a specific date and time, then it could be lying to you. Perhaps it is returning the current offset, but that is not fixed. The same location can cycle through multiple different offsets.

IMO, Services like that should not attempt to resolve an offset, but should instead return a time zone identifier, such as America/New_York.

You should probably read the timezone tag wiki, and you may also be interested in this post.

OTHER TIPS

If there is any chance of doing this in C#, I would think NODA Time would do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top