i'm a little lost in the timezone :)
I have data stored with the time in UTC. The server is in the Netherlands, so we live in utc+1 (now, with daylightsavingtime, in utc + 2)
Now a client says: give me the data from august 5th.
So i have to calculate the utc time from 'his time'. For that i have to know:
what is your utc offset (we stored that in his profile, let's say utc -6) are you in daylightsavingtime (because then we have to add +1 and make the utc offset -开发者_运维知识库5)
Then my questions:
Can i ask the .Net framework: does country XX have daylightsavingtime?
Can i ask the .Net framework: is 08-05-2010T00:00:00 in country XXX daylightsavingtime at that moment?
i've been trying the .ToLocalTime(), but this only gives me the local time at the server, and that's not what i want, i want to calculate with the timezone of the user, and also with the fact that at that particular point in time, if he/she is in daylightsavingtime
I've also seen this VB example:
TimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time")
Dim Dated As DateTime = TimeZoneInfo.ConvertTimeToUtc(TempDate, TimeZone)
but imho this doesn't take into account that the user in this timezone is or is not in a daylightsavingtime (dst) country. For instance, one user in this timezone is in the netherlands having dst, and one other is in another country which has no dst.
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.
精彩评论