본문 바로가기
NodeJS & Javascript

자바스크립트 js Date to int, int to Date 변환 프로그램

by Super Santj 2020. 5. 11.
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<p></p>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<div class="ui input"><input id="typeIntInput" type="number" placeholder="숫자를 입력하세요" /><button id="typeIntButton" class="ui primary button">변환</button></div>
<p>&nbsp;</p>
<div class="ui statistic">
<div id="resultDate" class="value">&nbsp;</div>
<br />
<div class="label">변환 값 입니다.</div>
</div>
<p><br /><br /></p>
<div class="ui input"><input id="typeDateInput" type="datetime-local" placeholder="날짜를 입력하세요" /><button id="typeDateButton" class="ui primary button">변환</button></div>
<p>&nbsp;</p>
<div class="ui statistic">
<div id="resultInt" class="value">&nbsp;</div>
<br />
<div class="label">변환 값 입니다.</div>
</div>
<script>
  const typeIntButton = document.getElementById('typeIntButton');
  const typeDateButton = document.getElementById('typeDateButton');
  const typeDateInput = document.getElementById('typeDateInput');
  const typeIntInput = document.getElementById('typeIntInput');
  const resultDate = document.getElementById('resultDate');
  const resultInt = document.getElementById('resultInt');
  typeIntButton.onclick = function(){
      let result = parseInt(typeIntInput.value);
      try{
        resultDate.innerHTML = new Date(result);
        typeIntInput.value = '';
      }catch(e){
          resultDate.innerHTML = '올바른 값을 입력해주세요 에러코드 =>'+e;
      }
    }
  typeDateButton.onclick = function(){
    let result = Date.parse(typeDateInput.value);
    try{
    	resultInt.innerHTML = result;
    	typeDateInput.value = '';
    }catch(e){
    	resultInt.innerHTML = '올바른 값을 입력해주세요 에러코드 =>'+e;
    }
  }
</script>

 

 

 

변환 값 입니다.



 

 

변환 값 입니다.

댓글