//日期格式转换 getCurrentTime() { var date = new Date();//当前时间 var year = date.getFullYear() //返回指定日期的年份 var month = this.repair(date.getMonth() + 1);//月 var day = this.repair(date.getDate());//日 var hour = this.repair(date.getHours());//时 var minute = this.repair(date.getMinutes());//分 var second = this.repair(date.getSeconds());//秒 //当前时间 var curTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; return curTime; }, //补0 repair(i){ if (i >= 0 && i <= 9) { return "0" + i; } else { return i; } }, //日期比较大小 CompareDate(d1,d2) { return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/")))); }
标签:repair,格式化,second,Js,date,日期,var,month From: https://www.cnblogs.com/QiangQiangDai/p/16810468.html