JSFiddle - React, Tailwind, and code Playground

by alexflav23

JavaScript

function diff(startTime, endTime) {
    var startTime = ('0' + startTime).slice(-4),
        endTime = ('0' + endTime).slice(-4),
        startH = startTime.substring(0,2),
        startMin = startTime.substring(2,4),
        endH = endTime.substring(0,2),
        endMin = endTime.substring(2,4),
        now = new Date(),
        year = now.getUTCFullYear(),
        month = now.getUTCMonth(),
        day = now.getDate(),
        startDate = new Date(year, month, day, startH, startMin),
        endDate = new Date(year, month, day, endH, endMin),
        startMinutes = (startDate.getHours() * 60) +  startDate.getMinutes(),
        endMinutes = (endDate.getHours() * 60) +  endDate.getMinutes();
    return endMinutes - startMinutes;
};