vue怎么展示当前时间(年/月/日)
Date()是可以直接获取当前时间的,但是格式不是我们需要展示的格式,所以通过getNowDate()中对Date()的年月日提取出来再对展示的格式进行调整。
·
最近打算把项目里的小细节都总结出来,就从获取当前时间开始吧
Date()是可以直接获取当前时间的,但是格式不是我们需要展示的格式,所以通过getNowDate()中对Date()的年月日提取出来再对展示的格式进行调整
<template>
<div class="time">
{{nowtime}}
</div>
</template>
<script>
export default {
data(){
return{
nowtime:""
}
},
mounted(){
this.getNowDate()
},
mounted(){
getNowDate(){
var year = new Date().getFullYear()
var month = new Date().getMonth()+1;
var day = new Date().getDate();
this.nowtime="("+year+"/"+month+"/"+day+")";
console.log(this.nowtime)
}
},
}
</script>
<style>
.tab{
width: 100%;
}
</style>
更多推荐
已为社区贡献1条内容
所有评论(0)