开发者

How to order a TimeZone list in .NET?

I have an ASP.NET web application that requires users to select their appropriate time zone so that it can correctly show local times for events.

In creating a simple approach for selecting the time zone, I started by just using the values from TimeZoneInfo.GetSys开发者_运维技巧temTimeZones(), and showing that list.

The only problem with this is that since our application is primarily targeted at the United States, I'd like to show those entries first, basically starting with Eastern Time and working backwards (West) until I reach Atlantic time.

What's a good approach to do this in code?


Using LINQ:

var timezones = TimeZoneInfo.GetSystemTimeZones();
var orderedZones = (from t in timezones
                                where t.DisplayName.Contains("(US & Canada)")
                                select t).Concat(
                                from t in timezones 
                                where t.DisplayName.Contains("(US & Canada)") == false
                                select t
                               );


Ok, so my solution: I put the display name, Id, and the order I wanted them in the database. It works, as I just store the Id in a user object anyway. I'll grab it once, and store it in the application cache.

Hack-y, but it "solves" the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜