JavaScript系列:Date对象

时间:2022-08-06 05:40:13

<script type="text/javascript">
    var oDate = new Date();
    var iYear = oDate.getFullYear();
    var iMonth = oDate.getMonth() + 1; // 月份是从0开始的
    var iDate = oDate.getDate();
    var iDay = oDate.getDay();
    switch (iDay) {
        case 0:
            iDay = "星期日";
            break;
        case 1:
            iDay = "星期一";
            break;
        case 2:
            iDay = "星期二";
            break;
        case 3:
            iDay = "星期三";
            break;
        case 4:
            iDay = "星期四";
            break;
        case 5:
            iDay = "星期五";
            break;
        case 6:
            iDay = "星期六";
            break;
    }
    document.write("今天是" + iYear + "年" + iMonth + "月" + iDate + "日," + iDay);
</script>