<script>
created() {
var g = new Date().getTime();//1637120820767
var d = new Date(g); //创建一个指定的日期对象
console.log(d);
console.log(this.formatDate(d));
},
methods:{
formatDate(now) {
var year = now.getFullYear(); //取得4位数的年份
var month = now.getMonth() + 1; //取得日期中的月份,其中0表示1月,11表示12月
var date = now.getDate(); //返回日期月份中的天数(1到31)
var hour = now.getHours(); //返回日期中的小时数(0到23)
var minute = now.getMinutes(); //返回日期中的分钟数(0到59)
var second = now.getSeconds(); //返回日期中的秒数(0到59)
return (
year +
"-" +
month +
"-" +
date +
" " +
hour +
":" +
minute +
":" +
second
);
}
}
</script>
Vue时间戳获取当前时间
最新推荐文章于 2024-05-31 14:28:02 发布