2020. 1. 29. 04:20
반응형
특정 날짜 2개의 차이를 구하기 위해 moment.js를 이용할 수 있다.
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment-with-locales.min.js"></script>
<input type='date' id='firstDate'/>
<input type='date' id='secondDate'/>
<button id='resultButton'>결과</button>
<br/>
<div id="resultDiv"></div>
<script>
$(function(){
$("#resultButton").click(function(){
if($("#firstDate").val() === "" || $("secondDate").val() === ""){
$("#resultDiv").text("Invalid Date");
}else{
var firstDate = moment($("#firstDate").val());
var secondDate = moment($("#secondDate").val());
var diff = secondDate.diff(firstDate, "days");
$("#resultDiv").text("Date diff: " + diff);
}
});
});
</script>
반응형
'dev' 카테고리의 다른 글
[Link] 온라인 C# 컴파일러 (0) | 2020.02.27 |
---|---|
[ASP.NET Core] 파일 업로드 기능 구현 (ajax, 멀티) (0) | 2020.02.26 |
[ASP.NET Core] 앱 재시작 없이 페이지 변경사항 반영 (0) | 2020.02.13 |
[JavaScript] ResizeSensor: HTML 엘리먼트 크기 변화 감지 (0) | 2020.02.13 |
[Python] Tkinter를 이용한 간단한 타이머 프로그램 (0) | 2020.01.27 |
[HTML] contenteditable 이용, div 편집 가능하도록 하기 (0) | 2019.11.13 |
[HTML/CSS] 테이블 헤더 고정 (ie에서는 안됨) (0) | 2019.10.20 |
[MSSQL] inserted 이용 입력한 Identity 얻기 (0) | 2019.10.18 |