I wanted to get start time and end time separately so I wrote code like this:
const date = new Date();
let start = date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 60 / 60;
function startRecord() {
document.getElementById("1").innerHTML = start;
}
function endRecord() {
let end = date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 60 / 60;
document.getElementById("2").innerHTML = end;
}
<p id="1">Show start time</p>
<p id="2">Show end time</p>
<button type="button" onclick="startRecord()">
start
</button>
<button type="button" onclick="endRecord()">
end
</button>
But I always got same result.
Start time and end time is same although I spent some time between them.
How can I get correct result?