Simple Countdown based on Date using JavaScript | Sanwebcorner

Simple Countdown based on Date using JavaScript

This Post help you how to create countdown based on your given date. It automatically takes the countdown using date you are provided. It displays the years, months, days, hours, minutes and seconds. It is very useful display the counter for the event launching and any other new product launching system.This countdown display with animation countdown cube.If you don't want display some fields like years then you should remove the fields in JavaScript.

You can change the date in your index.php script. Find the script code target: new Date( 'Feb 10, 2018 7:47:00' ), in index file and change the date according to your choice...

You can able to change the time zone in the below javscript code i am using here Asia/Kolkata the default time zone is UTC, It will convert the utc to Asia/Kolkata. This concept is build with given end time, It automatically calculated the years, months, days, hours, minutes, seconds and display the results in the cube div.

The below html code is used to display the full countdown
<div id='counter' class='counter'></div>
And the countdowncube.css file used design the counter boxes in a perfect manner you can able to change the styles and colors according to your choice to edit the countdowncube.css file. and the countdowncube.js have the javascripts to display the counter you can edit and customize the counters according to your choice.

I hope this simple concept is very useful to you. This example have the demo page please check out the demo page and download the full code and use it to your website.

Countdown based on given date:

<!DOCTYPE html>
<html class="no-js">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Simple Countdown based on Date using Jquery</title>
<meta name="description" content="Personal Website of Ali Cigari, jack of all trades...">
<meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=0">
<script src=""></script>

<link rel="stylesheet" href="countdowncube.css">
<style class="inlinestyle">
.counter {
margin: 10 auto;
text-align: center;
background-color: rebeccapurple;
<div id='counter' class='counter'></div>

<script src="countdowncube.js"></script>
var targetDate = new Date();
targetDate.setMonth(targetDate.getMonth() + 18)

var targetDateStringUTC = targetDate.toISOString()
.replace(':00.000', '');
var targetDateString = targetDateStringUTC.replace('Z', '');

var targetLADate =,
var tzLAOffset = targetLADate.substr(-6);
var targetDateStringOffset = targetDateString.replace('Z', '')
.replace(':00.000', '') +

var tzOldFormatOffset = targetDateString.substr(-5);
var targetDateOldFormatString = targetDate.toLocaleDateString() +
' ' + tzOldFormatOffset;

var pastDate = new Date();
pastDate.setMonth(targetDate.getMonth() - 18)
var targetDateStringPast = pastDate.toISOString()
.replace(':00.000', '');
var nearFutureDate = new Date();
nearFutureDate.setSeconds(nearFutureDate.getSeconds() + 10);
var nearFutureDateString = nearFutureDate.toISOString()
function reloadCounter(element_id,
triggerEnd) {


$(element_id).countdownCube( {
target: new_target,
targetTimezone: targetTimezone,
cubeSize: cubeSize,
background:  background,
color: color,
onEnd: onEnd,
triggerEnd: triggerEnd,
} );
$('#counter').countdownCube( {
target: targetDateStringUTC,
cubeSize: 150,
background:  '#ffff00',
color: 'blue',
} );

$('#counter-end-notrigger').countdownCube( {
target: targetDateStringPast,
targetTimezone: 'UTC',
cubeSize: 150,
background:  'lightcyan',
color: 'darkcyan',
target is in the past and triggerEnd is false,
so onEnd is not triggered when the page is loaded
onEnd: function(e) {
.text('This was the end, but it was not triggered! ' +
'(counter original target: ' +
e.options.targetDateObject.toISOString() +
} );
$('#counter-end-trigger').countdownCube( {
target: targetDateStringPast,
targetTimezone: 'UTC',
cubeSize: 150,
background:  'lightcyan',
color: 'cyan',
onEnd: function(e) {
.text('This was the end and it was triggered! ' +
'(counter original target: ' +
e.options.targetDateObject.toISOString() +
triggerEnd: true,
} );

target: new Date( 'Feb 10, 2018 7:47:00' ),
cubeSize: 50

Post a comment


360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap Bootstrap form validation border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed donation form download zip email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient heart animation hide menu Horizontal News ticker Hover Htm Html html dropdown html form html form validation html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript javascript validation Jquery jquery validation js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form multi-select-checkbox Multi-Step-form Multiple File Upload in PHP mysql News ticker on hover change text to image our team page password generator password strength checker paypal form paypal html form Photoshop PHP php mailer populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips whatsapp link website Whislist Youtube