js获取当前日期

var myDate=new Date(); 

var str="yyyy-MM-dd";
              str=str.replace(/yyyy|YYYY/,myDate.getFullYear());     
              str=str.replace(/MM/,parseInt(myDate.getMonth())+1>9?(parseInt(myDate.getMonth())+1).toString():"0" + (parseInt(myDate.getMonth())+1).toString());    
              str=str.replace(/dd|DD/,myDate.getDate()>9?myDate.getDate().toString():"0" + myDate.getDate().toString());

原文地址:https://www.cnblogs.com/tangxf/p/2836832.html