mercredi 13 novembre 2019

Hide Hour and Minute if 0

i'm trying to remove the Hours and the minutes if they are 0

Example ( If hours = 0 )

0 H, 1m, 12s
to
1m, 12s

and( If minutes = 0)

0m, 12s
to
12s

But if the hours is

2H, 0m, 12s (display like this)
2H, 12s (not like this if the minute is 0)

This is what i've tried, but this is so wrong

<script>
    var countDownDate = new Date(<?php echo strtotime($getdateinfo)*1000; ?>).getTime();
    var x = setInterval(function() {
    var now = new Date().getTime();
    var distance = countDownDate - now;
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var h = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var m = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var s = Math.floor((distance % (1000 * 60)) / 1000);

if (h = 0);{
document.getElementById("tts").innerHTML = m + "m " + s + "s ";
}
if (h = 0 & m = 0);{
document.getElementById("tts").innerHTML = s + "s ";
}
else{
    document.getElementById("tts").innerHTML = h + " h "
    + m + "m " + s + "s ";
}


}, 1000);
</script>

Aucun commentaire:

Enregistrer un commentaire