1.moment.js的使用,北京时间UTC转化正常年月日–
```javascript
formatTime() {
var moment = require("moment");
this.appList.forEach((item) => {
item.ctime = moment(item.ctime).format("YYYY-MM-DD HH:mm:ss");
});
},
在这里插入代码片
```formatTime() {
var moment = require("moment");
ctime.format("YYYY-MM-DD HH:mm:ss");
});
},
2.获取当前时间(年月日)
mytimes() {
let myDate = new Date();
let year = myDate.getFullYear();
let month = myDate.getMonth() + 1;
let day = myDate.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 0 && day <= 9) {
day = "0" + day;
}
this.todytime = year + "年" + month + "月" + day + "日";
},
3.获取今天的星期
data(){
weektimes: "",
weekdatas: ["日", "一", "二", "三", "四", "五", "六"],
}
weekdata() {
let week = new Date().getDay();
let str = "星期" + this.weekdatas[week];
this.weektimes = str;
},
4.时分秒倒计时
mounted() {
let times = new Date().getTime();
setInterval(() => {
this.formatter(times);
}, 1000);
},