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

看板Web_Design作者時間19年前 (2007/03/15 16:18), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
我寫了以下這段程式 希望能取得某月的最後一天 假設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; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.211.214.103

03/17 02:12, , 1F
我記得是只要先設定到下個月一號再減一天就行啦!
03/17 02:12, 1F
文章代碼(AID): #15-G5e6B (Web_Design)
文章代碼(AID): #15-G5e6B (Web_Design)