html中js通過指定的年月獲取該月的天數

由於2015年是平年, 所以2月份是28天。故下面彈出的數字是28

<script>

    alert(GetLastDay('2015', '2'));

    function GetLastDay(year, month) {
        var date = new Date(year, month, 1),
        lastDay = new Date(date.getTime() - 864e5).getDate();

        //alert(date.getTime());   
        return lastDay;
    }

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