計算當前日期是第幾天

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        function fun(){ 
            var year = document.getElementById('year').value;
            var month = document.getElementById('month').value;
            var day = document.getElementById('day').value;
            var sum_day;//總天數
            sum_day  =  new  Date(month  +  '-'  +  day  +  '-'  +  year);
            now_year  = new Date().getFullYear();
            one = new Date(1 + '-' + 1 + '-' + year);
            parseInt(Math.abs(sum_day  -  one)  /  1000  /  60  /  60  /24);
            alert(parseInt(Math.abs(sum_day  -  one)  /  1000  /  60  /  60  /24)+1);


        }
    </script>
</head>
<body>
    年: <input type="number" id="year"/><br/>
    月: <input type="number" id="month"/><br/>
    日: <input type="number" id="day"/><br/>
    <input type="button" id="" value="計算" οnclick="fun()"/><br/>

    
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章