You need to understand what a Date object represents and how it stores dates. Basically, each Date is a thin shell around the number of milliseconds since 1970 (the so-called era time). Subtracting one date from another, you do not get the date: you just get the number of milliseconds between them.
Assuming this line doesn't make much sense:
var diff = new Date(nu - tid1);
What you really need:
var diffMillis = nu - tid1;
... and then just extract seconds, minutes, etc .:
var seconds = Math.floor(diffMillis / 1000); var secondsPart = seconds % 60; var minutes = Math.floor(seconds / 60); var minutesPart = minutes % 60; var hoursPart = Math.floor(minutes / 60);
Working script .
Tomasz Nurkiewicz Dec 15 '12 at 16:10 2012-12-15 16:10
source share