js获取周几、获取前多少个小时

       getWeekDay(date) {
                let weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
                let week = weekArray[new Date(date).getDay()];//注意此处必须是先new一个Date
                return week;
            },
            timestampToTime(timestamp) {
                let date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
                let Y = date.getFullYear() + '-';
                let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                let D = date.getDate() + ' ';
                let h = date.getHours() + ':';
                let m = date.getMinutes() + ':';
                let s = date.getSeconds();
                return Y + M + D + h + m + s;
            },

 

posted @ 2021-04-10 09:27  韦邦杠  阅读(442)  评论(0编辑  收藏  举报