• HTML
  • JS
  • J볃교

SCRIPT로 남은기간+시간+요일 타이머

2018-11-09 198

설명

  • 카카오톡 링크

SCRIPT로 남은기간+시간 타이머를 구하는 소스입니다.

소스실행 현황

소스보기( X표시가 나타나면 무시하셔도 됩니다! )

<style>
	.text_info {display:inline-block; width:100%}
	.text_info p {display:inline-block; font-size:16px; font-weight:300; letter-spacing:-0.025em; line-height:1.2em}
	.date_time {display:inline-block; width:100%; text-align:center; padding:20px 0; margin-top:20px }
	.date_time span {font-size:16px; color:#404040; }
	.date_complete {}
	.date_complete.none {display:none}
</style>

<h3 class="view_h3 first_h3">1분뒤로 설정되어있습니다</h3>
<div class='date_time tbclr'>
	<span class="time"><em class="year"></em>.<em class="month"></em>.<em class="day"></em> (<em class='today_day'></em>) 오후 <em class="clock_wow"></em> : <em class="minute_wow" ></em> 시작! (남은시간 <em class="clock"></em>시 <em class="minute"></em>분 <em class="second"></em>초)</span>
</div>
<div class="date_complete none">
	완료되었습니다
</div>

<script type="text/javascript"> 
	function getTime() { 
		now = new Date(); 
		dday = new Date(now.getFullYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes()+1,00); 
		
		// 원하는 날짜, 시간 정확하게 초단위까지 기입.
		days = (dday - now) / 1000 / 60 / 60 / 24; 
		daysRound = Math.floor(days); 
		hours = (dday - now) / 1000 / 60 / 60 - (24 * daysRound); 
		hoursRound = Math.floor(hours); 
		minutes = (dday - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound); 
		minutesRound = Math.floor(minutes); 
		seconds = (dday - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound); 
		secondsRound = Math.round(seconds); 

		var week = new Array('일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일');

		var today = new Date().getDay();
		var todayLabel = week[today];
		//console.log(todayLabel);
		
		$(".clock").text(hoursRound);
		$(".minute").text(minutesRound);
		$(".second").text(secondsRound);
		$(".today_day").text(todayLabel);

		$(".year").text(now.getFullYear());
		$(".month").text(now.getMonth());
		$(".day").text(now.getDate());
		$(".clock_wow").text(now.getHours());
		$(".minute_wow").text(now.getMinutes() + 1);


		console.log(hoursRound+"/"+minutesRound+"/"+secondsRound);
		if(hoursRound == "0" && minutesRound == "0" && secondsRound == "1") {
			
			setTimeout(function() {
				$(".date_time").css({"display":"none"});
				$(".date_complete").removeClass("none");
			},1000);
			return false;
		} 
		newtime = window.setTimeout("getTime();", 1000); 
	}
	getTime();
</script>