mercredi 4 novembre 2020

how to calculate Time Difference in AM PM format

I am using jsp page and i want to calculate time diff in start time to end time and shoe to total time input which is readOnly="true" function TSTimediff(counter) {

var start = document.getElementById("activitylogFrom"+counter).value;
var end =   document.getElementById("activitylogTo"+counter).value;
if(start > end){
    alert("From Time Must Be less than To Time");
    console.log(start+":"+end)
}
else if(end > start){
    start.split(':');
    end.split(':');
    var startDate = new Date(0, 0, 0, start[0], start[1], 0);
    var endDate = new Date(0, 0, 0, end[0], end[1], 0);
    var total = endDate.getTime() - startDate.getTime();
    console.log(total)

    var hours = Math.floor(total / 1000 / 60 / 60);
    total -= hours * 1000 * 60 * 60;
    var minutes = Math.floor(total / 1000 / 60);
    return (hours < 9 ? "0" : "") + hours + ":" + (minutes < 9 ? "0" : "") + minutes;
    }
    
    total = document.getElementById("activitylogTotalTime");
    
 }
*emphasized text*



Aucun commentaire:

Enregistrer un commentaire