function getCurdate(){ var myDate = new Date(); var nowDateTime = myDate.getFullYear(); nowDateTime = nowDateTime + ((myDate.getMonth() + 1) < 10 ? "-0" + (myDate.getMonth() + 1) : "-" + (myDate.getMonth() + 1)); nowDateTime = nowDateTime + (myDate.getDate() < 10 ? "-0" + myDate.getDate() : "-" + myDate.getDate()); return nowDateTime; } console.log(getCurdate());