元旦まで何日間ですか?

6851 ワード

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //            
        var date = new Date() //       
        console.log(date)
        //         
        // console.log(Date.now()) 
        //       
        var nowTime = date.getTime()

        //           
        date.setMonth(0,1)
        //         
        var ydTime = date.getTime()
        console.log(date)

        //        ,             
        //           date  ,       ,       
        var days = (nowTime - ydTime) / 1000 / 60 / 60 / 24
        console.log(days)


        //               
        var date = new Date() //       
        console.log(date)
        //         
        // console.log(Date.now()) 
        //       
        var nowTime = date.getTime()

        //              
        date.setMonth(2,11)
        //         
        var ydTime = date.getTime()
        console.log(date)

        //        ,             
        //           date  ,       ,       
        var days = (nowTime - ydTime) / 1000 / 60 / 60 / 24
        console.log(days)


    </script>
</body>
</html>