js 展示当前时间

setNowTimes: function () {
    var myDate = new Date();
    // console.log(myDate)
    var wk = myDate.getDay();
    var yy = String(myDate.getFullYear());
    var mm = myDate.getMonth()+1;
    mm = String(mm < 10 ? '0' + mm : mm);
    var dd = String(myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate());
    var hou = String(myDate.getHours() < 10 ? '0' + myDate.getHours() : myDate.getHours());
    var min = String(myDate.getMinutes() < 10 ? '0' + myDate.getMinutes() : myDate.getMinutes());
    var sec = String(myDate.getSeconds() < 10 ? '0' + myDate.getSeconds() : myDate.getSeconds());
    var weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    var week = weeks[wk];
    this.nowDate = yy + '-' + mm + '-' + dd;
    this.nowTime = hou + ':' + min + ':' + sec;
    this.nowWeek = week;
}

 

posted @ 2021-01-19 17:45  蓝色土耳其  阅读(137)  评论(0编辑  收藏  举报