자바스크립트 카운트다운 알람 질문있습니다. 채택완료
물브
7년 전
조회 2,457
카운트다운을 하고있습니다. 지금은 코드가 아래와같아서 카운트다운 시간을 직접 입력을해야합니다.
저는 현재년도 현재월 현재일등 일자는 자동으로 갱신이되고 시간만 지정하면 해당 지정된시간에 카운트다운이 되길원합니다.
일종의 알람같은거죠 그런데 지금 시간셋팅하느부분에 년도랑 월 일 부분을 현재일로 바꾸면 될거같은데 그게 잘되지않아서 도움을 구합니다. 저는 매일 17:30:00시간까지 카운트 다운되는 알람시계?를 만들고싶습니다.
</p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">/*시간 카운트다운*/</span></p>
<p> </p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">// Set the date we're counting down to</span></p>
<p> </p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">var countDownDate = new Date("Jun 21, 2018 17:30:00").getTime();</span></p>
<p> </p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">// Update the count down every 1 second</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">var countdownfunction = setInterval(function() {</span></p>
<p> </p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> // Get todays date and time</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var now = new Date().getTime();</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> </span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> // Find the distance between now an the count down date</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var distance = countDownDate - now;</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> </span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> // Time calculations for days, hours, minutes and seconds</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var days = Math.floor(distance / (1000 * 60 * 60 * 24));</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> var seconds = Math.floor((distance % (1000 * 60)) / 1000);</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> </span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> // Output the result in an element with id="demo"</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> document.getElementById("demo").innerHTML = days + "d " + hours + "h "</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> + minutes + "m " + seconds + "s ";</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> </span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> // If the count down is over, write some text </span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> if (distance < 0) {</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> clearInterval(countdownfunction);</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> document.getElementById("demo").innerHTML = "퇴근완료";</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움"> }</span></p>
<p><span style="font-family:나눔고딕,NanumGothic,돋움">}, 1000);</span></p>
<p>
링크는 http://dhxn5ak.cafe24.com/out/metg.php" target="_blank">http://dhxn5ak.cafe24.com/out/metg.php 입니다.
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
답변을 작성하려면 로그인이 필요합니다.
로그인