How do you deal with the the DST or Summer time changes?
One can multiply the decimal hours by 60 minutes to obtain the number of minutes.
If one includes the start and end dates it is possible to convert the date time strings into the JavaScript date object and then perform the calculations using the various methods and properties of the JavaScript date object.
I would convert the times to minutes since midnight and then format the result to include leading zeros for the minutes.
// get start hours and minutes; var hrsStart = parseInt (this.getField("ST").value.split(":")[0]); var minStart = parseInt (this.getField("ST").value.split(":")[1]); // start time as minutes since midnight; var timeStart = (hrsStart * 60) + minStart; // get end hours and minutes; var hrsEnd = parseInt (this.getField("ET").value.split(":")[0]); var minEnd = parseInt (this.getField("ET").value.split(":")[1]); // end time as minutes since midnight; var timeEnd = (hrsEnd * 60) + minEnd; // compute difference in minutes; var timeRez = timeEnd - timeStart; // assume adjust for next day in minutes; if(timeRez < 0) { timeRez += (60 * 24); } // display in result in formatted hours and formatted minutes including leading zeros; event.value = util.printf("%,101d", Math.floor(timeRez / 60)) + ":" + util.printf("%,102d", (timeRez % 60));
... View more