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.
Add the local time offset to the UTC time. For example, if your local time offset is -5:00, and if the UTC time is shown as 11:00, add -5 to 11. The time setting when adjusted for offset is 06:00 (6:00 A.M.).
UTC uses 24-hour (military) time notation and is based on the local standard time on the 0° longitude meridian which runs through Greenwich, England.
UTC current time is 13:31:38 UTC current date is 14th Friday October 2022.
var now = new Date(); var utc = new Date(now. getTime() + now. getTimezoneOffset() * 60000);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With