PHP / Javascript create countdown between 2 times - javascript

I currently have many issues trying to think of how to create this script.
I currently have 2 variables :
$curHour = "15:25:00";
$endHour = "16:25:00";
I am struggling to find how to create a countdown specifcally between these times.
I would appreciate any help.
Greetings Glenn

I have just finished in javascript, but the code seems a little long.
html:
<div id="process"></div>
javascript:
var process = document.getElementById('process');
var cur = '15:25:00';
var end = '16:25:00';
cur = cur.split(':');
end = end.split(':');
var x = parseInt(cur[0], 10)*3600+parseInt(cur[1], 10)*60+parseInt(cur[2], 10);
var y = parseInt(end[0], 10)*3600+parseInt(end[1], 10)*60+parseInt(end[2], 10);
showTime(y);
var timer = setInterval(function(){
y--;
showTime(y);
if(y<=x){
clearInterval(timer);
}
}, 1000);
function showTime(diff){
var hour = parseInt(diff/3600, 10);
var minute = parseInt((diff - hour*3600)/60, 10);
var second = diff - hour*3600-minute*60;
hour = hour<10 ? '0'+hour : hour;
minute = minute<10 ? '0'+minute : minute;
second = second<10 ? '0'+second : second;
var time = hour+':'+minute+':'+second;
process.innerHTML = time;
}

You can try like below,
setInterval(function () {
var end = <?php echo strtotime('16:25:00')*1000;?>;//Javascriptcomapatible time
var current = new Date().getTime(); //Current timestamp
var seconds_left = (end - current) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
console.log(days + "d, " + hours + "h,"+ minutes + "m, " + seconds + "s");
}, 1000);

Related

Js ,how to make the time I rounded up can follow what's on my pc

here
I want the timer script that I made to follow the time on my pc, where is the wrong part of the code, please correct the wrong part of the code, thank you
enter code here
let countdown = new Date (new Date().getHours()
+ 1,0,1 );
let $hours = document.getElementById('hours');
let $minutes = document.getElementById('minutes');
let $seconds =document.getElementById('seconds')
setInterval(function() {
var now = new Date();
var timeleft = (countdown , now) / 1000;
updateclock(timeleft);
},1000);
function updateclock(remainingTime){
let hours = Math.floor(remainingTime / 3600) %
24;
remainingTime -= hours * 3600;
let minutes = Math.floor(remainingTime / 60) %
60;
remainingTime -= minutes * 60
let seconds = Math.floor(remainingTime % 60);
$hours.innerHTML = Number(hours);
$minutes.innerHTML = Number(minutes);
$seconds.innerHTML = Number(seconds);
}
function Number (Number) {
return Number < 10 ? + Number : Number;
}
subtracting one value from another does not reduce original variables, unless you explicitly assign result to one of them
anyway, the main problem was (countdown , now) statement, which should be actually: (countdown.valueOf() - now.valueOf())
let countdown = new Date ();
countdown.setHours(countdown.getHours()+1);
let $hours = document.getElementById('hours');
let $minutes = document.getElementById('minutes');
let $seconds =document.getElementById('seconds')
setInterval(function() {
var now = new Date();
var timeleft = (countdown.valueOf() - now.valueOf()) / 1000;
updateclock(timeleft);
},1000);
function updateclock(remainingTime){
remainingTime = parseInt(remainingTime, 10);
let seconds = remainingTime % 60;
remainingTime = Math.floor(remainingTime / 60);
let minutes = remainingTime % 60;
remainingTime = Math.floor(remainingTime / 60);
let hours = remainingTime;
$hours.innerHTML = Number(hours);
$minutes.innerHTML = Number(minutes);
$seconds.innerHTML = Number(seconds);
}
function Number (number) {
return (number >=0 && number < 10) ? ("0" + number) : number;
}
<span id="hours"></span> : <span id="minutes"></span> : <span id="seconds"></span>

APEX countdown timer between dates

I'm trying to display the countdown timer between an enddate/time column and the system date/time column using below code. It's not displaying the timer.
I have created a page item P3_TIMER and it has a column P3_STARTDATE.
var timer;
var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date
timer = setInterval(function() {
timeBetweenDates(endDate);
}, 1000);
function timeBetweenDates(toDate) {
var dateEntered = :P3_STARTDATE;
var now = new Date();
var difference = dateEntered.getTime() - now.getTime();
if (difference <= 0) {
// Timer done
clearInterval(timer);
} else {
var seconds = Math.floor(difference / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
$("#days").text(days);
$("#hours").text(hours);
$("#minutes").text(minutes);
$("#seconds").text(seconds);
}
$s('P3_TIMER',timer);
}
It's not possible to mix pl/sql and javascript. They're different languages and run in different environments.
function timeBetweenDates(toDate) {
var dateEntered = :P3_STARTDATE; >>> This is pl/sql
var now = new Date();
The P3_STARTDATE needs to be converted to a javascript date object. That cannot be directly, some parsing is needed as shown in this thread.
For the example below the assumption is made that the date is passed in format DD-MON-YYYY.
var timer;
var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date
timer = setInterval(function() {
timeBetweenDates(endDate);
}, 1000);
function parseDate(s) {
var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,
jul:6,aug:7,sep:8,oct:9,nov:10,dec:11};
var p = s.split('-');
return new Date(p[2], months[p[1].toLowerCase()], p[0]);
}
function timeBetweenDates(toDate) {
var dateEntered = parseDate(apex.item( "P63_DATE" ).getValue() );
var now = new Date();
var difference = dateEntered.getTime() - now.getTime();
if (difference <= 0) {
// Timer done
clearInterval(timer);
} else {
var seconds = Math.floor(difference / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
$("#days").text(days);
$("#hours").text(hours);
$("#minutes").text(minutes);
$("#seconds").text(seconds);
}
apex.item("P63_TIMER").setValue(`Days: ${days}, Hours: ${hours}, Minutes: ${minutes}, Seconds: ${seconds}`);
}

Countdown function not working correctly in timeout block

I can't get the second countdown function to work correctly in the first Snippet. I fire off cdtd(); a second time for that. Both cdtd(); functions do not collide and are in inside anonymous functions. When I fire off cdtd(); the first time I get a working countdown timer until 16:00:00. When I fire off it for the second time I will not get a working countdown timer until 17:00:00. This is the actual use case of this question.
Just to made an example flow I made a second snippet. Both cdtd(); do collide eachother but the second cdtd(); function call will give a working countdown timer back. Now I still don't know why it's not working in the first snippet. Havint there a timeOut function I work with.
I'm not sure what is wrong. Anyone has got a clue?
Here is the script. https://jsfiddle.net/3fq2j6a1/
I tried to run the countdown scripts under eachother and that works but I don't need that :) function cdtd() { .. }
Here is a snippet:
// First session
var sessie1 = new Date();
var totsessie1 = new Date(sessie1.getFullYear(), sessie1.getMonth(), sessie1.getDate(), 14, 16, 0, 0) - sessie1;
if (totsessie1 < 0) {
totsessie1 += 86400000; // it's after 10am, try 10am tomorrow.
}
setTimeout(function() {
document.getElementById("test1").innerHTML = "Message.";
// First countdown
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16, 0, 0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds to go!";
timer = setTimeout(cdtd, 1000);
}
cdtd();
// End first countdown
}, totsessie1);
// Second session
var sessie2 = new Date();
var totsessie2 = new Date(sessie2.getFullYear(), sessie2.getMonth(), sessie2.getDate(), 14, 17, 0, 0) - sessie1;
if (totsessie2 < 0) {
totsessie2 += 86400000; // it's after 10am, try 10am tomorrow.
}
setTimeout(function() {
document.getElementById("test1").innerHTML = "Message.";
// Second countdown
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 0, 0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds to go!";
timer = setTimeout(cdtd, 1000);
}
cdtd();
// End second countdown
}, totsessie2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="test1">This is a paragraph.</p>
<span id="time"></span>
Here is the snippet of the code when I use the countdown scripts under eachother.
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 15, 0, 0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " min and " + seconds + " seconds to go! (countdown to line 49)";
timer = setTimeout(cdtd, 1000);
}
cdtd();
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16, 0, 0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " min and " + seconds + " seconds to go! (countdown to line 49)";
timer = setTimeout(cdtd, 1000);
}
cdtd();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="test1">This is a paragraph.</p>
<span id="time"></span>
https://jsfiddle.net/edfcLzhw/
But I need them inside the session blocks. When doing that I will get a different time left with the second countdown timer. totsessie1(); totsessie2();
The countdown script comes from: Javascript countdown defined with hours
I solved this for now. I did not make the code correctly on 2 points.
First thing. I used the function totsessie1() also being the second totsessie1() function. I changed the second to totsessie2(). I also didn't use clearInterval(timer); before running the second cdtd();.
Here is a working snippet of the end goal:
// First session
var sessie1 = new Date();
var totsessie1 = new Date(sessie1.getFullYear(), sessie1.getMonth(), sessie1.getDate(), 15, 25, 0, 0) - sessie1;
if (totsessie1 < 0) {
totsessie1 += 86400000; // it's after 10am, try 10am tomorrow.
}
setTimeout(function() {
document.getElementById("test1").innerHTML = "Message.";
// First countdown
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(),now.getMonth(),now.getDate(),16,0,0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds to go!";
timer = setTimeout(cdtd, 1000);
}
cdtd();
// End first countdown
}, totsessie1);
// Second session
var sessie2 = new Date();
var totsessie2 = new Date(sessie2.getFullYear(), sessie2.getMonth(), sessie2.getDate(), 15, 26, 0, 0) - sessie2;
if (totsessie2 < 0) {
totsessie2 += 86400000; // it's after 10am, try 10am tomorrow.
}
setTimeout(function() {
document.getElementById("test1").innerHTML = "Message.";
// Second countdown
clearInterval(timer);
function cdtd() {
var now = new Date();
var dolazak = new Date(now.getFullYear(),now.getMonth(),now.getDate(),17,0,0);
var timeDiff = dolazak.getTime() - now.getTime();
if (timeDiff <= 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = '';
}
//if(minutes < 2){document.getElementById(id).style.color="#ff0000";};
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById('time').innerHTML = " Still " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds to go!";
timer = setTimeout(cdtd, 1000);
}
cdtd();
// End second countdown
}, totsessie2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<p id="test1">This is a paragraph.</p>
<span id="time"></span>
</body>
</html>
JSFiddle: https://jsfiddle.net/nwvk8h12/

how to freeze countdown at 00:00:00:00 when timer is ends

I want to freeze my timer at 00:00:00:00 when the timer ends how to do that?
That would be very appreciated.
Thanx
here is my code,
// set the date we're counting down to
var target_date = new Date("Jul 3, 2014").getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second
setInterval(function () {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
// format countdown string + set tag value
countdown.innerHTML = days + "d, " + hours + "h, "
+ minutes + "m, " + seconds + "s";
}, 1000);
HTML
<span id="countdown"></span>
Since you wouldn't need the interval any more, you can replace:
setInterval(function () {
With:
var myInterval = setInterval(function () {
Then, after:
var seconds_left = (target_date - current_date) / 1000;
Insert:
if(seconds_left <= 0){
seconds_left = 0;
clearInterval(myInterval);
}
This clears the interval when the timer reaches 0 seconds, and makes sure the code displays 0's, properly.
So, this'll be your code then:
var target_date = new Date("Jul 3, 2014").getTime();
var days, hours, minutes, seconds;
var countdown = document.getElementById("countdown");
var myInterval = setInterval(function () {
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
if(seconds_left <= 0){
seconds_left = 0;
clearInterval(myInterval);
}
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
countdown.innerHTML = days + "d, " + hours + "h, "
+ minutes + "m, " + seconds + "s";
}, 1000);
Add a simple IF to the end of your function:
// format countdown string + set tag value
if(days > 0 || hours > 0 || minutes > 0 || seconds > 0)
countdown.innerHTML = days + "d, " + hours + "h, "
+ minutes + "m, " + seconds + "s";
else
countdown.innerHTML = 0 + "d, " + 0 + "h, "
+ 0 + "m, " + 0 + "s";
Before write your actual time into your div, you must check first, if one or more of values are bigger than 0
So your code will be like:
// set the date we're counting down to
var target_date = new Date("Jul 3, 2014").getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second
setInterval(function () {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
// format countdown string + set tag value
if(days > 0 || hours > 0 || minutes > 0 || seconds > 0)
countdown.innerHTML = days + "d, " + hours + "h, "
+ minutes + "m, " + seconds + "s";
else
countdown.innerHTML = 0 + "d, " + 0 + "h, "
+ 0 + "m, " + 0 + "s";
}, 1000);
Here is working JSFiddle

Multiple Javascript Countdowns on the Same Page

Hi I'm trying to add several javascript countdowns to a single html page. I have included the .js file below. Right now my page only displays the first countdown.
function cdtd () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd()',1000);
}
function countdown () {
var end = new Date("May 31, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('countdown()',1000);
}
function cdtd3 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd3()',1000);
}
function cdtd4 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd4()',1000);
}
function cdtd5 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd5()',1000);
}
function cdtd6 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %=60;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd6()',1000);
}
There are several problems you need to fix here:
Each of your countdown timers uses the same element IDs when it stores the time strings. That's why only one of them shows up.
If any of your countdowns reaches zero, the document.write() call will erase the entire page.
The code is repeated over and over again. This should be one common function for all your countdowns. (What if you need to add one more? Ten more?)
While multiple timers would work, you don't need them. Run a single timer and update all your displayed times from it.
When you call setInterval(), it's better to pass a function reference as the first parameter instead of a string.
Give those ideas some thought and see what you can come up with, then report back with your new code. :-)
Right now you are referencing one box overwriting each value everytime you call the function.
You want to use a query selector instead of getElementById.
Here is a simple example using jQuery:
var cdtd = function(id,end) {
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
$( id + " .days").html(days);
$( id + " .hours").html(hours);
$( id + " .minutes").html( minutes);
$( id + " .seconds").html( seconds );
console.log(id + " .hoursBox",$( id + " .hoursBox").length,id,end,hours,minutes,seconds)
var timer = setTimeout(function(){cdtd(id,end)},1000);
}
cdtd("#counter1",new Date("December 25, 2014 00:01:00"));
cdtd("#counter2",new Date("October 31, 2014 00:01:00"));
cdtd("#counter3",new Date("January 1, 2014 00:01:00"));
http://plnkr.co/8LrtWvfGnZWyRYl2RlWd
#Shanimal i m used this code on my website,problem is that when timer reached 0000 then it goes another page and shows deal ended.what i want ,when timer reach 0000 it should must display message on same page on specific div.it should not go for another page.i have tried it by removing
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
it does not shows any message even when it reached 0000 it start to count again from -1 - 1 -1 -1

Categories

Resources