其他分享
首页 > 其他分享> > js获取周几、获取前多少个小时

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;
            },

 

标签:week,Date,js,获取,let,date,new,周几,getMonth
来源: https://www.cnblogs.com/weibanggang/p/14639588.html