Convert somebody's local time to the UTC time

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 04:02:17

You can't ask the framework about a particular country - but you can ask about a particular time zone.

TimeZoneInfo does take DST into account. (Heck, it wouldn't have the IsDaylightSavingTime method otherwise.) If you've got two users, one of whom is currently observing DST and the other of whom isn't, then they aren't in the same time zone.

If you could specify which locations you're talking about, I could try to find out which time zones are involved. (It's generally easier to find out the Olson names, but it shouldn't be impossible to find out the Windows IDs.)

TimeZone class has a method IsDaylightSavingTime that take a date as parameter and return a boolean indicating if that date in in daylightsavingtime for that timezone.

I promote my comment to an answer. It appears to be a complicate problem. Look at http://www.timeanddate.com/time/dst2010.html, there is a table of DST in various country of the world. You cannot get this with static code because DST change not only from country to country, but also from year to year.

I guess you have to maintain a table with DST information and get information from it.

Or you can query a webservice to get such infos.

Look at http://www.earthtools.org/webservices.htm#timezone for a webservice that you can query to get time in various country that take in account DST (it work only for Western Europe time zones). Also look at http://www.geonames.org/export/web-services.html. You have to get your users geolocation to use these services.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!