Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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) ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...