Jump to content

Script Countdown - Javascript


xhakon
 Share

Recommended Posts

<html>
<body>
	<script>
	function updateTimer() {
		var obj = new Date(), 						// cream un obiect folosind new Date(); acest obiect va fi folosit pentru a lua ora exacta,
			sec = obj.getTime(), 					// Stocam milisecundele trecute de la 1 Ianuarie 1970 (nu stiu sigur data) intr-o variabila "sec"
			hours, minutes, days; 					// cream doua alte variabile in care vom stoca orele trecute, respectiv minutele si zilele
		sec = sec - 1474126639215; 					// scadem din ms actuale ms care erau intr-un anumit moment in timp.
		sec = Math.floor(sec / 1000);				// impartim numarul de secunde la 1000 pentru a afla secundele si le aproximam prin lipsa
		days = Math.floor(sec / (60 * 60 * 24)); 	// impartim secundele pentru a avea zilele
		sec = sec % (60 * 60 * 24);					// folosim operatorul % pentru a stoca restul ramas. (invatati voi la info ce e %)
		hours = Math.floor(sec / (60 * 60));		// Repetam...
		sec = sec % (60 * 60);
		minutes = Math.floor(sec / 60);
		sec = sec % (60);
		document.getElementById("countdown").innerHTML = "<b>Timpul trecut de la crearea acestui cod: </b> " +
		days + " days, " + ((hours < 10) ? ("0" + hours) : hours) + ":" + ((minutes < 10) ? ("0" + minutes) : minutes) + ":" + ((sec < 10) ? ("0" + sec) : sec); //setam continutul elementului
		
	}
	setInterval(updateTimer, 1000);
	updateTimer();
	</script>
	<p id = "countdown">Calculating...</p>
</body>
</html>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...