js ---- small case from one day how many days

From one day how many days left, JS cases, in fact, very simple, but I'm stuck somewhere, and a long time to want to understand

And there are a number of milliseconds required to process into minutes and seconds of the day, somehow stuck in here, I'm really stupid;

function mschange(num) {
    var num1 = parseInt(num / 1000);
    var miao = parseInt(num1 % 60);//
    var minute = parseInt((num1 / 60) % 60);//
    var hour = parseInt((num1 / 60 / 60) % 24);//小时
    var day = parseInt(num1 / 60 / 60 / 24);//
    return {
        'miao': miao,
        'minute': minute,
        'hour': hour,
        'day': day
    }
}

The above code will milliseconds days into minutes and seconds, accidentally stuck in here, and then I want to understand the problem units; The following is the complete code of good cases

 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>09距离某个日期还有多少</title>
</head>

<body>
    <h1>09距离某个日期还有多少天</h1>
    <input type="date" id="end">
    <input type="button" value="点我" id="btn">
    <div id="output"></div>
</body>
<script>where),
        end = document.getElementById ( 'End'each),
        BTN = document.getElementById ( 'BTN'were() {
        Function
    (= document.getElementById Output ( 'Output' ); 

        btn.onclick = function () {
             // requirements: end time - day = number of milliseconds -> days 
            var endTime = end.value;
             var _endTime = Date.parse (endTime);
             var the startTime = Date.now (); // Get today epoch time (1970-1-1 zero to several milliseconds) 
            var RES = _endTime - the startTime; // milliseconds 
            // var = Math.ceil Days (RES / 1000/60/60/24); 
            // the console.log (days); 
            // every second year, month, day 
            var Times = mschange (RES); 

            the console.log (Times);
            output.innerHTML= `Left: $ {times.day} days $ {times.hour} h $ {times.minute} $ {times.miao} second sub`; 
        } 
function mschange (NUM) {
     var num1 = the parseInt (NUM / 1000 );
     var Miao = the parseInt (num1 60%); // second 
    var minute = the parseInt ((num1 / 60) 60%); // sub   
    var hour = the parseInt ((num1 / 60/60) 24%); // h 
    var day = the parseInt (num1 / 60/60/24); // day 
    return {
         'Miao' : Miao,
         'minute' : minute,
         'hour' : hour,
         'day' : day
    }
}
    })();
</script>

</html>

 

Guess you like

Origin www.cnblogs.com/muyun123/p/11425539.html