Easy way: without daylight saving time
Like explained here there is a function getTimezoneOffset()
to get the timezone of the user.
But you have to know in witch timezone you are, in my example you are in the timezone UTC+0.
var myTimezone = 1;
var usersTimezone = (new Date()).getTimezoneOffset() / 60;
var timeDifference = Math.abs(myTimezone + usersTimezone) + " hours";
document.getElementById("time").innerHTML = "Time Difference: " + timeDifference;
<div id="time">
</div>
Calculation with daylight saving time
The code below also looks at he daylight saving time.
This is more complex and i used the momentjs for this.
Take also a look at this post:
https://stackoverflow.com/a/29268535/2801860
var now = moment();
var usersOffset = now.utcOffset();
now.tz("Europe/Berlin"); // your time zone, not necessarily the server's
var myOffset = now.utcOffset();
var diffInMinutes = Math.abs(usersOffset - myOffset);
document.getElementById("time").innerHTML = "Time Difference: " + (diffInMinutes/60);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone-with-data.min.js"></script>
<div id="time">
</div>