title: Javascript Time Difference Calculation
body: <p>I have this function        </p>
  
  <pre><code>function timeCalculator(form)
  {
      var currentTimeAndDate = new Date();
      var userTimeAndDate = form.userDate.value;
      var userUTCOffset2 = form.userUTCOffset.value;
      var userDate = new Date(userTimeAndDate);
      var tzDifference = currentTimeAndDate.getTimezoneOffset() + (userUTCOffset2 - currentTimeAndDate.getTimezoneOffset());
      var timeDifference = new Date((userDate.getTime()+(tzDifference*60*1000))-(currentTimeAndDate.getTime()+(userDate.getTimezoneOffset()*60*1000)));
  
      var hours = Math.floor(timeDifference.getTime() / 36e5),
      minutes = Math.floor(timeDifference.getTime() % 36e5 / 60000),
      seconds = Math.floor(timeDifference.getTime() % 60000 / 1000);
  
      document.getElementById('result').innerHTML = "There is exactly "+hours+" hours,"+minutes+"minutes and "+seconds+" seconds left until your specified time.";
  }
  </code></pre>
  
  <p>What this is supposed to do is a user inputs a time, date and UTC offset in a form and based on that it calculates how much time is left until that point. The minutes and seconds seem to work fine, but there is a problem with the hours. Anyone have any suggestions or maybe a different approach to something like this? Also how can I add days, months, years in the difference?</p>