개발자의 공부방/Frontend 날짜 계산 - 728x90 반응형 var loadDt = new Date(); //현재 날짜 및 시간 //현재시간 기준 계산 alert(new Date(Date.parse(loadDt) - 30 * 1000 * 60 * 60 * 24)); //30일전 alert(new Date(Date.parse(loadDt) - 15 * 1000 * 60 * 60 * 24)); //보름전 alert(new Date(Date.parse(loadDt) - 7 * 1000 * 60 * 60 * 24)); //일주일전 alert(new Date(Date.parse(loadDt) - 1 * 1000 * 60 * 60 * 24)); //하루전 alert(new Date(Date.parse(loadDt) + 1 * 1000 * 60 * 60 * 24)); //하루후 alert(new Date(Date.parse(loadDt) + 7 * 1000 * 60 * 60 * 24)); //일주일후 alert(new Date(Date.parse(loadDt) + 15 * 1000 * 60 * 60 * 24)); //보름후 alert(new Date(Date.parse(loadDt) + 30 * 1000 * 60 * 60 * 24)); //한달후 alert(new Date(Date.parse(loadDt) + 1000 * 60 * 60)); //한시간후 alert(new Date(Date.parse(loadDt) + 1000 * 60)); //1분후 alert(new Date(Date.parse(loadDt) + 1000)); //1초후 // 날짜를 입력 하면 오늘 날짜로부터 숫자만큼 전날의 날짜를 mm/dd/yyyy 형식으로 돌려 준다. function caldate(day){ var caledmonth, caledday, caledYear; var loadDt = new Date(); var v = new Date(Date.parse(loadDt) - day*1000*60*60*24); caledYear = v.getFullYear(); if( v.getMonth() < 9 ){ caledmonth = '0'+(v.getMonth()+1); }else{ caledmonth = v.getMonth()+1; } if( v.getDate() < 9 ){ caledday = '0'+v.getDate(); }else{ caledday = v.getDate(); } return caledmonth+'/'+caledday+'/'+caledYear; } 반응형 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기준수한쭈니네 저작자표시 (새창열림) Contents 당신이 좋아할만한 콘텐츠 vue] vue.js 경로 '@' 의미 2021.11.29 Vue] vue JS 시작. 2021.11.26 자바스크립트] 비밀번호 확인하기. 2021.03.16 JSTL selectbox 시간 분 나타내기 feat. option value 값도 함께 2020.07.13 댓글 0 + 이전 댓글 더보기