🏫 TECH/🖼️ Front [javascript] 오픈소스를 사용하여 쉽게 날짜 구하기 728x90 안녕하세요. 말랑고양입니다.프로젝트를 진행하는 도중 날짜를 구해야되는 일이 있어 포스팅하게 되었습니다.현재 날짜로부터 15일 전의 날짜를 YYYYMMDD 형식으로 가져와야 했습니다.아래와 같은 소스코드를 사용하면 쉽게 구할 수 있습니다.MIT 라이센스가 걸려있는 moment.js를 사용하였습니다.다른 방법도 있겠지만, 개인적으로 자바스크립트로 날짜를 구할때는 moment.js 이용을 추천드립니다 ^ ^123456789101112<script type="text/javascript" src="./moment.js"></script><script> var today = new Date(); var formattedDate = moment(today).format('YYYYMMDD'); alert(formattedDate); var pastday = new Date(Date.parse(today) - 15 * 1000 * 60 * 60 * 24); //현재 날짜 및 시간 var formattedPastDate = moment(pastday).format('YYYYMMDD'); alert(formattedPastDate); </script>Colored by Color Scriptercs도움이 되셨다면 '공감' 한 번씩 눌러주세요 ^ ^추가로 궁금한 점이 있으시다면 댓글 남겨주세요. 감사합니다. Moment.js is freely distributable under the terms of the MIT license.#reference : https://momentjs.com/moment.jsexample.html 반응형 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기팀드모네 IT Blog 저작자표시 비영리 동일조건 '🏫 TECH > 🖼️ Front' 카테고리의 다른 글 html에 html file을 inlcude하는 가장 쉬운 방법 (0) 2018.05.17 html 또는 js 코드를 깔끔하게 정렬해주는 사이트 (0) 2018.05.16 [google firebase] how to firebase hosting init (0) 2018.05.05 [javascript] 파이어베이스 회원가입/로그인 성공 여부 체크 방법 (0) 2018.04.23 [sweetalert] swal text br(next-line) tag (0) 2018.04.12 Contents 당신이 좋아할만한 콘텐츠 html에 html file을 inlcude하는 가장 쉬운 방법 2018.05.17 html 또는 js 코드를 깔끔하게 정렬해주는 사이트 2018.05.16 [google firebase] how to firebase hosting init 2018.05.05 [javascript] 파이어베이스 회원가입/로그인 성공 여부 체크 방법 2018.04.23 댓글 0 + 이전 댓글 더보기