// js判断当月有多少天; findDayByYearMonth(year, month) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; break; case 2: return this.isRunYears(year) ? 29 : 28; break; case 4: case 6: case 9: case 11: return 30; break; } } //被四整除(不被100整除)的是闰年,其中可以被100整除的同时必须被400整除的才是闰年,其余的就是平年 isRunYears(year) { return year%4== 0? (year%100 == 0? (year%400==0? true:false) :true) : false; } getTime (str) { str = str.replace(/ GMT.+$/, '');// Or str = str.substring(0, 24) var d = new Date(str); var a = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()]; for (var i = 0, len = a.length; i < len; i++) { if (a[i] < 10) { a[i] = '0' + a[i]; } } str = a[0] + '-' + a[1] + '-' + a[2] + ' ' + a[3] + ':' + a[4] + ':' + a[5]; return str }, var time= 'Mon May 16 2022 18:48:34 GMT+0800 (中国标准时间)'; console.log(getTime(time)); //"2022-05-16 18:48:34"