vue自定义动态时钟显示
vue自定义动态时钟显示
效果:
一秒动一次
代码:
<div class="time">{{ nowTime }}
</div>
data() {return {nowTime:null,}},methods:{getNowFormatDate(v) {let date=v;let y = date.getFullYear();let m = date.getMonth() + 1;m = m < 10 ? "0" + m : m;let d = date.getDate();d = d < 10 ? "0" + d : d;let h = date.getHours();h = h < 10 ? "0" + h : h;let minute = date.getMinutes();minute = minute < 10 ? "0" + minute : minute;let second = date.getSeconds();second = second < 10 ? "0" + second : second;this.nowTime = h + ":" + minute + ":" + second;// return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;}, //转日期方法,可以根据需要加上年月日nowTimes() {this.getNowFormatDate(new Date());setInterval(this.nowTimes, 1000);this.clear();},clear() {clearInterval(this.nowTimes);this.nowTimes = null;},}
mounted() {this.nowTimes();},
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!