[英]My JavaScript Function is does not calculate the hours
This is My JavaScript code这是我的 JavaScript 代码
function date(){
var starth = document.getElementById("stime").vlue;
var endh= document.getElementById("etime").value;
var duration = parseFloat(endh) - parseFloat(starth);
var noOfDays = Math.floor(duration / (1000*60*60*24));
var noOfHours = Math.floor(duration % (1000*60*60*24) / (1000*60*60));
var noOfMinutes = Math.floor(duration % (1000*60*60) / (1000*60));
var noOfSeconds = Math.floor(duration % (1000*60) / 1000);
document.getElementById("tlecture").value = noOfHours + "hours" + noOfMinutes + "minutes" + noOfSeconds + "seconds";
}
This is My Form这是我的表格
<form class="form-inline" method="post">
<div class="form-group">
<label for="name">Lecture Name: </label> <br>
<br> <input type="text" id="search-box" name="search-box" size="60" />
<div id="suggesstion-box" align="center" ></div>
</div>
<br><br>
<div class="form-group">
<label for="cname">Course Name: </label></br>
<br> <input type="text" id="search-box_2" name="search-box_2" required placeholder="Search By Name..." size="60" />
<div id="suggesstion-box_2" align="center"></div>
</div>
<div class="form-group">
<label for="stime">Start Time: </label></br>
<br> <input type="time" id="status" name="stime" size="60" required="true" />
<label for="etime">End Time: </label></br>
<br> <input type="time" id="etime" name="etime" size="60" required="true" />
</div>
<div class="form-group">
<label for="cname">Total Lecture : </label></br>
<br> <input type="text" id="tlecture" name="tlecture" size="60" />
<button class="btn btn-primary" name="submit" onclick="date()"> Calculate</button>
</div>
<button type="submit" class="btn btn-primary" name="submit" style=" position: absolute; bottom: 62%;"> Submit </button>
</form>
My Javascript function is not working.我的 Javascript function 不工作。 When I click the calculate button, I want to get the total hours the lecture has worked.
当我点击计算按钮时,我想获得讲座的总小时数。 The lecture can enter the start time and end time from the form.
讲座可以从表格中输入开始时间和结束时间。 I wrote a function to calculate the total hours but it's not working.
我写了一个 function 来计算总小时数,但它不起作用。 I try to debug via console but nothing showed in the console.
我尝试通过控制台进行调试,但控制台中没有显示任何内容。 Can someone help me out?
有人可以帮我吗? I want to enter the start time and end time after that I want to calculate the total hours.
我想输入开始时间和结束时间,然后我想计算总小时数。
<script>
function date(){
p = "1/1/1970 ";
var starth = document.getElementById("stime").value;
var endh= document.getElementById("etime").value;
var difference = new Date(new Date(p+endh) - new Date(p+starth)).toUTCString().split(" ")[4];
document.getElementById("tlecture").value = difference;
}
</script>
Here is the answer for my question.这是我的问题的答案。 This is the correct calculation
这是正确的计算
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.