How to add current time HH:MM with extra HH:mm using Jquery or Javascript? RRS feed

  • Question

  • User-893002196 posted

    Hi All,

    I have function:-

    function getTimeInterval(startTime, endTime, lunchTime) {
    var start = moment(startTime, "HH:mm");
    var end = moment(endTime, "HH:mm");
    var minutes = end.diff(start, 'minutes');
    var interval = moment().hour(0).minute(minutes);
     interval.subtract(lunchTime, 'minutes');
    return interval.format("HH:mm");

    var EndTimeRegularWkHr = getTimeInterval("09:00", "08:30"); But the result desire is not 17:30.

    Please advise.



    Monday, April 8, 2019 1:17 AM


  • User-893317190 posted

    Hi micnie2020 ,

    Not clear about your requirement, what result do you want to get?

    From your function , you get the minute difference between  startTime and endTime and set new moment's minute to  the calculated minutes.

    Finally return the HH:mm format of the moment.

    What do you want to get from this function?

    If you want to use js , you could refer to the code below.

     var date = new Date("0000-01-01 09:00");  // initialize a Date and set its time to 09:00
            date.setHours(date.getHours() + 5, date.getMinutes() + 30); //date.getHours() + 5 adds 5 hours to current hour and set date's hour to the new hour, minutes is the same
            console.log(date.getHours() + ":" + date.getMinutes()); // show the new hour and minutes

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 8, 2019 7:21 AM