开发者

how to get the date-time for a particular city in C#? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Web service - current time zone for a city?

Just wondering whether there is a public web service (w开发者_JS百科ithout reading from local machine time zone) that I could use to get the current date-time in that city using C#.


You can use GeoNames to get the time zone. From that and the current UTC time, you can work out the local time. (You can also download the GeoNames data to avoid having to make a remote call.)

Note that GeoNames uses the Olson time zone names - there are various mappings from those to Windows time zone names around on the net for use with TimeZoneInfo, or (plug) you could use Noda Time to perform the UTC to local time conversion. While there are aspects of Noda Time which are unfinished, that part should work fine.


GeoNames has one.


There would have to exist a way for a Computer to know where it was located.

Computers, by and large, have no idea where they are.

That said, you could write something into your code that could set/specify where it was, then go from there using UTC.


A commercial one

http://worldtimeengine.com/api

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜