남은시간 (디데이) 카운트 : 자바스크립트 > 그누보드5 팁자료실

그누보드5 팁자료실

남은시간 (디데이) 카운트 : 자바스크립트 정보

남은시간 (디데이) 카운트 : 자바스크립트

본문

 

targetTime = "2022-09-01-13:30:00"; 

위의 변수만 동일한 패턴으로 년도-월-일-시간:분:초 로 넣어줍니다.

월,일,시간,분,초 가 한 자리 단위일 때는 앞에 0을 붙여 두 자리로 만듭니다.

 


<link href="https://fonts.googleapis.com/css2?family=Lato&display=swap" rel=stylesheet>
<style>
#countSpan { font-family:Lato; font-weight:bold; font-size:4rem; }
#countSpan span { font-size:2rem; }
</style>
<script>
targetTime = "2022-12-25-13:30:00";
document.write("<span id='countSpan'></span>");
targetCount = targetTime.split("-")[1] + "-" + targetTime.split("-")[2] + "-" + targetTime.split("-")[0] + "-" + targetTime.split("-")[3];
function countInterval() {
    countTime = new Date(targetCount) - new Date();
    countDay = Math.floor(countTime / (1000 * 60 * 60 * 24)) < 1 ? "" : Math.floor(countTime / (1000 * 60 * 60 * 24)) + "<span>일</span> ";
    countHour = ("0" + Math.floor(countTime % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))).slice(-2) + ":";
    countMinute = ("0" + Math.floor(countTime % (1000 * 60 * 60) / (1000 * 60))).slice(-2) + ":";
    countSecond = ("0" + Math.floor(countTime % (1000 * 60) / 1000)).slice(-2);
    if (countTime < 1) {
        countSpan.innerHTML = "이벤트 종료";
        clearInterval(countMode);
    }
    else countSpan.innerHTML = countDay + countHour + countMinute + countSecond;   
}
countInterval();
countMode = setInterval(countInterval, 1000);
</script>

 

게시판에서 여분필드로 표현할 때는 예를 들어 wr_1 일 때는 뷰페이지에서

targetTime = "<php echo $view['wr_1']; ?>";

로 표현해주면 되겠지요.

추천
5
  • 복사

댓글 18개

활용도가 좋네요 ^^

적용해보니 뷰페이지에선 카운팅이 되는데 리스트에는 왜 안될까요 ?

그리고,
targetTime = "<php echo $view['wr_1']; ?>";  하면


NaN일 aN:aN:aN


이렇게 나옵니다 ^^;
© SIRSOFT
현재 페이지 제일 처음으로