日期的格式化年月日星期

      var date = new Date(),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate(),
            week = date.getDay(),
            str = '',
            hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
            minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
            second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            month >= 1 && month <= 9 ? (month = "0" + month) : "";
            day >= 0 && day <= 9 ? (day = "0" + day) : "";
            if (week == 0) {  
                    str = "周日";  
            } else if (week == 1) {  
                    str = "周一";  
            } else if (week == 2) {  
                    str = "周二";  
            } else if (week == 3) {  
                    str = "周三";  
            } else if (week == 4) {  
                    str = "周四";  
            } else if (week == 5) {  
                    str = "周五";  
            } else if (week == 6) {  
                    str = "周六";  
            }  

 

posted @ 2020-04-01 13:44  曦雨幽兰  阅读(949)  评论(0编辑  收藏  举报