I would like to create a function to calculate/sum the time. For Example I work 40 hours per week and I want to sum all hours and minutes of each Day which I worked to find out how many hours did I work. I tried with Moment.js but no luck :/
var fTime = document.querySelector('input[id="fromTime"]').value;
var tTime = document.querySelector('input[id="toTime"]').value;
var btn = document.querySelector(".btn");
var sum = document.querySelector(".sum");
var reset = document.querySelector(".reset");
btn.onclick = sumTimes;
function sumTimes(){
sum.innerHTML = "You Worked " + tTime + " hours";
reset.style.opacity = 1;
}
reset.onclick = (e)=>sum.innerHTML = "00:00"
div.hours{
width:300px;
background-color:red;
heigth:70px;
text-align:center;
color:white;
display:flex;
flex-direction:column;
align-items:center;
}
.hours > *{
margin:3px;
}
.reset{
opacity:0;
}
<div class="wrapper">
<div class="hours">
<h2>Your Time</h2>
<label for="fromTime">From: </label>
<input id="fromTime" type="time" name="fromTime" value="13:30">
<label for="toTime">To: </label>
<input id="toTime" type="time" name="toTime" value="14:30">
<button class="btn">Enter</button>
<div class="sum">00:00</div>
<button class="reset">Reset</button>
</div>
</div>