The following line in my code:
var timezoneoffset = new Date().getTimezoneOffset();
returns -120.14933013916015.
I was expecting that the return value will be 120, and in general, that the value is always an integer.
Can anyone explain this? Right now it seems like I'll need to perform a round operation on the result.
The getTimezoneOffset() method returns the difference, in minutes, between a date as evaluated in the UTC time zone, and the same date as evaluated in the local time zone.
Offset from Coordinated Universal Time. Offset from Coordinated Universal Time represents the difference in hours and minutes between UTC and the local system time. A negative offset indicates that the time is west of UTC and a positive offset indicates that the time is east of UTC.
To get the current browser's time zone, you can use the getTimezoneOffset() method from the JavaScript Date object. The getTimezoneOffset() returns the time difference, in minutes, between UTC time and local time.
I have tried everything I can think of, and cannot reproduce the problem you are reporting.
The only thing I can think of is that something else in your code is modifying the Date
prototype. Perhaps you are using some date/time library that you didn't tell us about?
Please try reproducing the problem in a clean empty console.
about:blank
in the URL barnew Date().getTimezoneOffset()
into the console.Does it still show the decimals?
Date
prototype.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