獲取當(dāng)前時(shí)間展示為05-08的形式,只有月日如果只有一位數(shù)就補(bǔ)0,兩位正常顯示,這是現(xiàn)在的寫法,可不可以優(yōu)化一下我覺得現(xiàn)在寫的比較麻煩?constmyDate=newDate();consttoday=myDate.toLocaleDateString().split('/').join('-');lettimes=today.split('-');constYear=times[0];constMonth=times[1];constDay=times[2];letmounth='';if(Month.length===1){mounth='0'+Month}else{mounth=Month}letday='';if(Day.length===1){day='0'+Day}else{ay=Day}constNewtoday=mounth+'-'+day;
獲取當(dāng)前時(shí)間展示為05-08的形式,只有月日如果只有一位數(shù)就補(bǔ)0,優(yōu)化?
回首憶惘然
2019-05-19 20:47:52