3

I have seen this which gets date of a one time zone from another time zone but what I want is to find out which timezone the user is in and then get date accordingly.

My website is current using this script to count the time till new year. I just realized that if the user is on a different time zone the timer will not be correct. So how do I find the time difference between the present date and new year depending on the users location.

    var daysSpan = document.getElementById("days");
    var hoursSpan = document.getElementById("hours");
    var minutesSpan = document.getElementById("minutes");
    var secondsSpan = document.getElementById("seconds");
    var c=1;
    function updateClock(){
        var t = Date.parse('January 1 2016 00:01:05') - Date.parse(new Date());
        if (t<=0 && c==1)
        {
            c--;
            window.open("http://www.its2016.weebly.com","_self");
        }
        var seconds = Math.floor( (t/1000) % 60 );
        var minutes = Math.floor( (t/1000/60) % 60 );
        var hours = Math.floor( (t/(1000*60*60)) % 24 );
        var days = Math.floor( t/(1000*60*60*24) );
        daysSpan.innerHTML = days;
        hoursSpan.innerHTML = hours;
        minutesSpan.innerHTML = minutes;
        secondsSpan.innerHTML = seconds;
    }
    setInterval(updateClock,1000);
Community
  • 1
  • 1
m0bi5
  • 8,900
  • 7
  • 33
  • 44

1 Answers1

3

By default, when you use new Date(); it automatically get the local system hour.

See the documentation here.

If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.

Thomas Kerbrat
  • 106
  • 1
  • 7
  • Thanks a lot, had a feeling the new Date() gets local time. Just wanted to clarify – m0bi5 Nov 14 '15 at 18:31
  • I'm glad it helped you :) It's always a good thing to read the docs. Also, try to get better on Google searching because I found the answer in less than two minutes. – Thomas Kerbrat Nov 14 '15 at 18:35