Re: [問題] 取某月的最後一天

看板Web_Design作者 (神聖光芒)時間19年前 (2007/03/15 17:41), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《ceritaff ()》之銘言: : 我寫了以下這段程式 希望能取得某月的最後一天 : 假設yearmonth = 96/03 : 則outputdate = 96/03/31 : 可是當我取 8月或9月時 outputdate = 96/09/NaN : 其他月份則可正常取得最後一天的日期 : 請問這段程式是哪邊有問題呢?? : function getMonthlastday(yearmonth){ : var thisyear = yearmonth.substring(0,2); : var thismonth = yearmonth.substring(3,5); : var nextdate = new Date(); : var y = parseInt(thisyear)+1911; : var m = parseInt(thismonth); : nextdate.setFullYear(y , m, 1); : nextdate.setDate(nextdate.getDate()-1); : var lastday = nextdate.getDate(); : var outputdate = thisyear + "/" + thismonth + "/" + lastday ; : return outputdate; : } 我試了一下,ie6.0跑沒問題,你用什麼瀏覽器,我跑的結果 for(i=1;i<13;i++){ document.write(getMonthlastday("96/"+i) + "<br>"); } 輸出: 96/1/31 96/2/28 96/3/31 96/4/30 96/5/31 96/6/30 96/7/31 96/8/31 96/9/30 96/10/31 96/11/30 96/12/31 -- 太初有,道即是 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.99.222.55

03/22 13:48, , 1F
感謝...
03/22 13:48, 1F
文章代碼(AID): #15-HIofB (Web_Design)
文章代碼(AID): #15-HIofB (Web_Design)