Why does the time zone offset return different values?

My location in GMT +5: 30

When I try to find getTimezoneOffset using JavaScript

 var x = new Date(); var currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60; 

I get a value of -5.5 . Curious when I do the same with C #

 var localZone = TimeZone.CurrentTimeZone; var localOffset = localZone.GetUtcOffset(new Date()); var currentTimeZoneOffsetInHours = localOffset.TotalHours; 

The return value is 5.5 .

Is this sign redesigned or do I not see anything important?

+4
source share
1 answer

JavaScript getTimeZoneOffset returns the offset to be added at local time to go to UTC. (The description of "time zone offset from UTC" is misleading, IMO.)

.NET GetUtcOffset returns the offset that must be added to UTC to get to local time, which is a more conditional IMO approach. This is just another reference point, basically.

Note that if you are using .NET 3.5 or later, you really should use TimeZoneInfo instead of TimeZone .

+6
source

Source: https://habr.com/ru/post/1436126/


All Articles