Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript's getTimezoneOffset returns wrong offset?

My computer's timezone is GMT-7:00 Mountain time US & Canada. I tried a javascript example on w3cschool:

<html>
<body>

<script type="text/javascript">
var d=new Date()
var gmtHours = -d.getTimezoneOffset()/60;
document.write("The local time zone is: GMT " + gmtHours);
</script>

</body>
</html>

The result is: The local time zone is: GMT -6

Why does this function return an offset with 1 hour difference from the actual timezone on my machine?

like image 778
Georgie Porgie Avatar asked Oct 23 '25 21:10

Georgie Porgie


1 Answers

You're currently in Mountain Daylight Time.

Let's think about another similar scenario. If your friend open on Android smartphone, is there any variable?

Can it return 0 if a user disables Javascript on Android or when he installed VPN app or other privacy Android app?

What does it mean 0 from new Date().getTimezoneOffset()? Is the user telling he is living in Australia a real liar? Or it can be from other programmatic blocking?

like image 180
Matthew Flaschen Avatar answered Oct 25 '25 12:10

Matthew Flaschen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!