I have a function which among other things does a conversion from Utc to Local and vice-versa. The problem is that when I run it on a PC with Win 7 it works OK, but when I run it on a PC with Vista the conversion goes wrong.
ex: My current time zone is +2 UTC
MyCurrentTime is set to 27.09.2012, 19:00 and the DateTimeKind is Unspecified.
DateTime utcTime = DateTime.SpecifyKind(MyCurrentTime,DateTimeKind.Utc);
DateTime localTime = new DateTime();
localTime = utcTime.Date.ToLocalTime();
The output on Win 7 is 27.09.2012, 17:00
The output on Vista is 27.09.2012, 04:00
Any ideas why this happens?
Thanks.
The solution was the one suggested by https://stackoverflow.com/users/570150/v4vendetta.
Both the Win 7 and Vista machines "agreed" on the correct time.
localTime= TimeZone.CurrentTimeZone.ToLocalTime(utcTime);
Thanks a lot!
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