欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在Vue中获取实时的日期和时间?

最编程 2024-08-08 18:01:56
...
methods: {
    getCurrentTime() {
        //获取当前时间并打印
        var _this = this;
    let yy = new Date().getFullYear();
    let mm = new Date().getMonth()+1;
    let dd = 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;
    console.log(_this.gettime)  
    }
}                              

结果如下: