Umwandle Sekunden in Tage, Stunden, Minuten und Sekunden
Ich habe ein JavaScript-Timing-Ereignis mit einer Endlosschleife und einer Stopptaste.
Es werden Zahlen angezeigt, wenn die Starttaste gedrückt wird. Jetzt möchte ich, dass diese Zahlen in etwa 4 Stunden, 3 Minuten, 50 Sekunden umgewandelt werden.
var c = 0;
var t;
var timer_is_on = 0;
function timedCount() {
document.getElementById('txt').value = c;
c = c + 1;
t = setTimeout(function() {
timedCount()
}, 1000);
}
function doTimer() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}
$(".start").on("click", function() {
//var start = $.now();
//alert(start);
//console.log(start);
doTimer();
$(".end").show();
$(".hide_div").show();
});
$(".end").on("click", function() {
stopCount();
});
.hide_div {
display: none;
}
.end {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="start">Start</p>
<p class="end">End</p>
<p class="hide_div">
<input type="text" id="txt" />//display numbers eg 12345
</p>
Wie konvertiere ich Zahlen wie 123456 in 1 Tag, 4 Stunden, 40 Minuten, 45 Sekunden?