이번달 마지막 날짜

이번달 시작 부터 이번달 끝 날짜 구하기.

특정 월을 입력 하면 시작일 ~ 끝일이 표현 됩니다.



( ex : 2019-01 )


~




// 이번달 첫날, 마지막날   // 2019-01-01   2019-01-31

function getDateFL(FL){


var toMonth = $("#toMonth").val();

var year = toMonth.substring(0,4);

var month = toMonth.substring(5,7);

var lastDay = (new Date(year,month,0)).getDate();  // 마지막날

day = "01"; // FL == F면 첫날


// 마지막날

if(FL == "L"){

day = lastDay;

return year + "-" + month  + "-" + day;

}


function search(){

$("#s").val(getDateFL('F'));

$("#e").val(getDateFL('L'));

}


// 문서가 준비되면

$(document).ready(function(){

var date = new Date();

var year = date.getFullYear();

var month = (date.getMonth()+1);

month = month >= 10 ? month : '0' + month;

$("#toMonth").val(year+"-"+month);


search();

});



 <input type="text" id="toMonth" value="" />  <input type="button" value="확인"  onclick="search();" />  ( ex : 2019-01 )

 <br/>

  <br/>

   <br/>

 <input type="text" id="s" value="" readonly /> ~  <input type="text" id="e" value="" readonly />





이 글을 공유하기

댓글

Designed by JB FACTORY