vue获取new date().gettime() 时间戳
在处理按钮显示的时候发现一个问题:
vue 通过new date().gettime()获取时间戳返回的是13位数字,单位是毫秒;
php后台time()获取的时间戳是10位数字,单位秒;
所以在判断比较时需要将time()*1000 转换为毫秒再去比较
<el-button v-if="new date(scope.row.end_time*1000).gettime()>new date().gettime()" size="mini" icon="edit" @click="editgroupsaction(scope.$index, scope.row)">编辑</el-button>
vue动态获取当前时间
获取当前时间:
<template>
<div id="home">
<span class="deadline">截止{{ gettime }}</span>
</div>
</template>
<script>
export default {
name: "home",
data() {
return {
gettime: "", //当前时间
};
},
methods: {
gettime() {
var _this = this;
let yy = new date().getfullyear();
var mm =
new date().getmonth() > 9
? new date().getmonth() + 1
: new date().getmonth() == 9
? new date().getmonth() + 1
: '0' + (new date().getmonth() + 1);
var dd = new date().getdate() < 10 ? '0' + new date().getdate() : new date().getdate();
let hh = new date().gethours();
let mf =
new date().getminutes() < 10 ? '0' + new date().getminutes() : new date().getminutes();
let ss =
new date().getseconds() < 10 ? '0' + new date().getseconds() : new date().getseconds();
_this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
},
currenttime() {
setinterval(this.gettime, 1000);
},
},
mounted() {
this.currenttime();
},
};
</script>
<style scoped>
</style>
获取当前日期:
<template>
<div id="home">
<span class="deadline">当前日期{{ sendtime }}</span>
</div>
</template>
<script>
export default {
name: "home",
data() {
return {
sendtime: "", //当前时间
};
},
mounted() {
this.format();
},
methods: {
format() {
const nowdate = new date();
const date = {
year: nowdate.getfullyear(),
month: nowdate.getmonth() + 1,
date: nowdate.getdate(),
}
const newmonth = date.month > 9 ? date.month : '0' + date.month
const day = date.date > 9 ? date.date : '0' + date.date
this.sendtime = date.year + '.' + newmonth + '.' + day
}, //获取当前时间
},
};
</script>
<style scoped>
</style>总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论