When I run var d = new Date; alert(d.toLocaleString())
in jsFiddle, or in the w3Schools "Tryit Editor", it is able to detect the location that I have set my computer to and report the correct time for that location (or at least, the one I had chosen at page load), taking into account its time zone and whether it uses Daylight Saving Time. The getTimezoneOffset()
method also reports the correct offset for my chosen location. However, when I use this javascript in my webpage and leave the browser to interpret it, I get different behaviors by browser:
- In Chrome, it always alerts the time in my real-life location, rather than the one I've chosen in the OS.
- In Firefox, it fails to take DST into account in any location besides my real-life one, and reports the time one hour before my system time.
- In Safari, it works like jsfiddle.
Can anyone explain these discrepancies, and suggest how I can get my website to behave like jsfiddle does?
edit: http://jsfiddle.net/5p8tL/, versus:
<html>
<body>
<script>
var d = new Date;
alert(d.toLocaleString());
</script>
</body>
</html>