开发者

World Time Widget - Display the time in a city

开发者 https://www.devze.com 2023-02-11 03:36 出处:网络
I need to implement a world time widget that will allow a user to select a city, hit a 开发者_如何学JAVAbutton and display the time in that city for them.

I need to implement a world time widget that will allow a user to select a city, hit a 开发者_如何学JAVAbutton and display the time in that city for them.

Has anyone got any pointers for me please?


Take a look at the TimeZoneInfo class (MSDN Link). This class, introduced in .net 3.5 handles most of the heavy lifting for you.

The steps to do what you're asking is as follows:

  1. In your dropdown list of cities, set the value for each city as their TimeZoneInfo DisplayName. See here for how to use the TimeZoneInfo.GetSystemTimeZones method. This will take a bit of work but, thanksfully, you'll only have to do this once.
  2. When a user selects a city, use the TimeZoneInfo.ConvertTime method to convert the time and you're done.

There are several different methods in the TimeZoneInfo class and a closer inspection will get you to your solution.


You could use some existing API allowing you to fetch the time given a city name. Another possibility is download World Time Zones database locally and integrate in your application.

0

精彩评论

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