Vue js displays the current time, date and time formatting, obtain the week, Vue date of transfer of the week

  • Get the current time
nowTime: new Date(), // 当前时间
nowWeek: '星期', //星期几
  • Date Format
filters: {
    formatDate(time) {
      var moment = require("moment");
      return moment(time).format("YYYY-MM-DD");
    }
  },
  • To convert dates to the week
var dateArray = nowTime.split("-");
var date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
var week = "星期" + "日一二三四五六".charAt(date.getDay());
this.nowWeek = week // 赋值本地数据
alert(week)
Published 18 original articles · won praise 10 · views 50000 +

Guess you like

Origin blog.csdn.net/a350110085/article/details/84887264