Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Very simple JavaScript countdown source code

Posted on July 23, 2023July 23, 2023 by Habibie

In case you need to make a countdown in your website, here is a handy JavaScript code you can use. Just edit the variable countDownDate and set it the date you want, then run the JS. Watch the console log counting the seconds. It will show an alert message when the countdown reaches zero.

<!DOCTYPE html>
<html>
	<head>
		<title>Simple Countdown</title>
	</head>
	<body>
		

		<script>
			
			//Countdown date:
			var countDownDate = new Date("2023-7-26 5:27").getTime();
			var x = setInterval(function() {

				var now = new Date().getTime();

				var distance = countDownDate - now;

				var days = Math.floor(distance / (1000 * 60 * 60 * 24)).toString();
				var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString();
				var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)).toString();
				var seconds = Math.floor((distance % (1000 * 60)) / 1000).toString();
				
				console.log("days: " + days + " hours: " + hours + " minutes: " + minutes + " seconds: " + seconds);

				// If the count down is finished...
				if (distance < 0) {
					clearInterval(x);
					alert("Countdown Ended!");
				}
			}, 1000);
		</script>
	</body>
</html>
Post Views: 369
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme