var nowDate = new Date();//当前时间var year = nowDate.getFullYear();//获取年var month = nowDate.getMonth() + 1 < 10 ? \"0\" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;//获取月份,两位不够补0var day = nowDate.getDate() < 10 ? \"0\" + nowDate.getDate() : nowDate.getDate();//获取日期,两位不够补0var dateStr = year + \"-\" + month + \"-\" + day;结果:2020-07-312019-11-11
js获取日期yyyy-MM-dd
未经允许不得转载:爱站程序员基地 » js获取日期yyyy-MM-dd