vue 时间戳转换成日期时间或日期
data: {message: 'Hello Vue,欢迎来到测试页面!',list: ['a.jpg', 'b.jpeg', 'g.gif', 'd.gif', 'e.jpeg', 'f.gif', 'h.gif', 'i.gif'],items: [{...
·
data: {
message: 'Hello Vue,欢迎来到测试页面!',
list: ['a.jpg', 'b.jpeg', 'g.gif', 'd.gif', 'e.jpeg', 'f.gif', 'h.gif', 'i.gif'],
items: [{
va: '1',
ts: "1570677732"
}, {
va: '1',
ts: "1570677755"
}, {
va: '1',
ts: "1570677766"
}, {
va: '1',
ts: "1570677788"
}]
},
methods: {
click(index) {
alert(`${index},欢迎来到测试页面`)
let arr = []
this.items.map(item => {
let obj = {
ts: this.unixTimeToDateTime(item.ts)
}
arr.push(obj)
})
this.items = arr
let data = this.unixTimeToDateTime(1570677732)
console.log(this.items)
},
unixTimeToDateTime(unixtime) {
var now = new Date(unixtime * 1000); // 依情况进行更改 * 1
y = now.getFullYear();
m = now.getMonth() + 1;
d = now.getDate();
return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
},
unixTimeToDate(unixtime) {
var d = new Date(parseInt(unixtime) * 1000); // 依情况进行更改 * 1
return (d.getFullYear()) + '-' + (d.getMonth() + 1 > 9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1)) + '-' + (d.getDate() > 9 ? d.getDate() : '0' + d.getDate());
}
},
更多推荐
已为社区贡献5条内容
所有评论(0)