<template>
<div>
<button @click="onClick">GET</button>
{{p1}}<br>{{p2}}<br>{{p3}}<br>{{p4}}<br>{{p5}}<br>{{p6}}
</div>
</template>
<script>
export default {
data(){
return{
p1:'',p2:'',p3:'',p4:'',p5:'',p6:''
}
},
methods:{
onClick(){
this.p1=Date.parse(2021-5-3);//Date.parse用来计算距离1970/1/1的时间戳
this.p2=new Date("2009/1/1"); //new Date("xxxx/x/x")用来文本显示时间
this.p3=new Date()//new Date不加参数,文本显示当前时间
this.p4=Date.parse(new Date());//目前时间的时间戳不算毫秒
this.p5=new Date().getTime();//目前时间的时间戳1
this.p6=(new Date()).valueOf();//目前时间的时间戳2
}
}
}
</script>
var myDate = new Date();
var year = myDate.getFullYear(); //获取完整的年份(4位,1970-???)
var month = myDate.getMonth()+1; //获取当前月份(1-12)
var day = myDate.getDate(); //获取当前日(1-31)
//获取完整年月日
var newDay = year + “-” + month + “-” + day;