I have tried to create multiple countdown timers in a table that will rely on variables to set its time left. Currently there are no results output to the page and I'm not sure why.
Ideally, this should display 4 countdown timers
var table;
table = ("<table>");
for (i = 0; i < 4; i++) {
table += ("<tr>");
table += ("<td> Time Left : </td>");
table += ("<td><div id=\"dday" + i + "\"></div></td>");
table += ("<td><div id=\"dhour" + i + "\"></div></td>");
table += ("<td><div id=\"dmin" + i + "\"></div></td>");
table += ("<td><div id=\"dsec" + i + "\"></div></td>");
table += ("</tr>");
}
table += ("</table>");
document.getElementById('listinglist').innerHTML = table;
var yr = 2016,
m = 2,
d = 3,
hr = 4,
min = 5;
for (i = 0; i < 4; i++) {
countdown(yr, m, d, hr, min, i);
}
var year = 2010;
var month = 12;
var day = 21;
var hour = 18;
var minute = 38;
var tz = -5;
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
function countdown(yr, m, d, hr, min) {
theyear = yr;
themonth = m;
theday = d;
thehour = hr;
theminute = min;
var today = new Date();
var todayy = today.getYear();
if (todayy < 1000) {
todayy += 1900;
}
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring1 = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
var todaystring = Date.parse(todaystring1) + (tz * 1000 * 60 * 60);
var futurestring1 = (montharray[m - 1] + " " + d + ", " + yr + " " + hr + ":" + min);
var futurestring = Date.parse(futurestring1) - (today.getTimezoneOffset() * (1000 * 60));
var dd = futurestring - todaystring;
var dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
var dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
var dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
var dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
document.getElementById('dday').innerHTML = dday;
document.getElementById('dhour').innerHTML = dhour;
document.getElementById('dmin').innerHTML = dmin;
document.getElementById('dsec').innerHTML = dsec;
setTimeout("countdown(theyear,themonth,theday,thehour,theminute)", 1000);
}
<div id="listinglist"></div>
There are few problems in your script, like you are calling the count down function before the montharray is created, you are not using the i part in getElementById etc
var table;
table = ("<table>");
for (i = 0; i < 4; i++) {
table += ("<tr>");
table += ("<td> Time Left : </td>");
table += ("<td><div id=\"dday" + i + "\"></div></td>");
table += ("<td><div id=\"dhour" + i + "\"></div></td>");
table += ("<td><div id=\"dmin" + i + "\"></div></td>");
table += ("<td><div id=\"dsec" + i + "\"></div></td>");
table += ("</tr>");
}
table += ("</table>");
document.getElementById('listinglist').innerHTML = table;
var yr = 2016,
m = 2,
d = 3,
hr = 4,
min = 5;
var year = 2010;
var month = 12;
var day = 21;
var hour = 18;
var minute = 38;
var tz = -5;
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
//should be called after setting the montharray
for (i = 0; i < 4; i++) {
countdown(yr, m, d, hr, min, i);
}
function countdown(yr, m, d, hr, min, i) {
theyear = yr;
themonth = m;
theday = d;
thehour = hr;
theminute = min;
var today = new Date();
var todayy = today.getYear();
if (todayy < 1000) {
todayy += 1900;
}
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring1 = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
var todaystring = Date.parse(todaystring1) + (tz * 1000 * 60 * 60);
var futurestring1 = (montharray[m - 1] + " " + d + ", " + yr + " " + hr + ":" + min);
var futurestring = Date.parse(futurestring1) - (today.getTimezoneOffset() * (1000 * 60));
var dd = futurestring - todaystring;
var dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
var dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
var dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
var dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
//need to target the elements using i in the id
document.getElementById('dday' + i).innerHTML = dday;
document.getElementById('dhour' + i).innerHTML = dhour;
document.getElementById('dmin' + i).innerHTML = dmin;
document.getElementById('dsec' + i).innerHTML = dsec;
//need to pass the parameter as passed to this function
setTimeout(countdown.bind(this, yr, m, d, hr, min, i), 1000);
}
<div id="listinglist"></div>
Related
I have jQuery function timer.
(function( $ ){
$.fn.makeTimer = function(val){
var val = val;
setInterval(function() {
var result;
var startTime = new Date(val);
startTime = (Date.parse(startTime) / 1000);
var now = new Date();
now = (Date.parse(now) / 1000);
var timePassed = now - startTime;
var years = Math.floor(timePassed / (86400 * 365));
var months = Math.floor((timePassed / (86400 * 30.41)) - (years * 12));
var days = Math.floor((timePassed / 86400) - (years * 365) - (months * 30.41));
var hours = Math.floor( (timePassed / 3600 ) - (years * (24 * 365)) - (months * (24 * 30.41)) - (days * 24) ) ;
var minutes = Math.floor( (timePassed / 60) - ( years * (1440 * 365) ) - (months * (1440 * 30.41)) - (days * (60 * 24)) - (hours * 60 ) );
var seconds = Math.floor(timePassed - (years * (86400 * 365)) - (months * (86400 * 30.41)) - (days * 86400) - (hours * 3600) - (minutes * 60) );
if (months < "10") { months = "0" + months; }
if (days < "10") { days = "0" + days; }
if (hours < "10") { hours = "0" + hours; }
if (minutes < "10") { minutes = "0" + minutes; }
if (seconds < "10") { seconds = "0" + seconds; }
console.log(hours + ":" + minutes + ":" + seconds);
result = hours + ":" + minutes + ":" + seconds;
return result;
}, 1000);
};
})( jQuery );
$("#timers").makeTimer("07 April 2022 13:00:00 GMT+07:00");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="timers"></div>
And I call like this,
$("#timers").makeTimer("07 April 2022 13:00:00 GMT+07:00");
This is the HTML element,
<div id="timers"></div>
After tried to run the code, I can't print/echo the text into $("#timers"), but when I try to console.log(hours + ":" + minutes + ":" + seconds); I can see the value.
What I want, how to return result correctly into this element?
Add at the top of your function:
var $element = this;
Then, after calculating results:
$element.text(result)
If you need all the values:
$element.append(`<br />${result}`)
(function( $ ){
$.fn.makeTimer = function(val){
var val = val;
var $element = this;
setInterval(function() {
var result;
var startTime = new Date(val);
startTime = (Date.parse(startTime) / 1000);
var now = new Date();
now = (Date.parse(now) / 1000);
var timePassed = now - startTime;
var years = Math.floor(timePassed / (86400 * 365));
var months = Math.floor((timePassed / (86400 * 30.41)) - (years * 12));
var days = Math.floor((timePassed / 86400) - (years * 365) - (months * 30.41));
var hours = Math.floor( (timePassed / 3600 ) - (years * (24 * 365)) - (months * (24 * 30.41)) - (days * 24) ) ;
var minutes = Math.floor( (timePassed / 60) - ( years * (1440 * 365) ) - (months * (1440 * 30.41)) - (days * (60 * 24)) - (hours * 60 ) );
var seconds = Math.floor(timePassed - (years * (86400 * 365)) - (months * (86400 * 30.41)) - (days * 86400) - (hours * 3600) - (minutes * 60) );
if (months < "10") { months = "0" + months; }
if (days < "10") { days = "0" + days; }
if (hours < "10") { hours = "0" + hours; }
if (minutes < "10") { minutes = "0" + minutes; }
if (seconds < "10") { seconds = "0" + seconds; }
console.log(hours + ":" + minutes + ":" + seconds);
result = hours + ":" + minutes + ":" + seconds;
$element.text(result);
return result;
}, 1000);
};
})( jQuery );
$("#timers").makeTimer("07 April 2022 13:00:00 GMT+07:00");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="timers"></div>
I just can't figure why this doesn't work for some odd values.
For example when trying to convert 22.68 to hours and minutes the output is 22:40.800000000000004 (Seconds shouldn't even appear)
if (str_HR_PER_WEEK.indexOf('.') > -1)
{
var str_HR_PER_WEEK_hrs = str_HR_PER_WEEK.substring(0 , str_HR_PER_WEEK.indexOf('.'));
var str_HR_PER_WEEK_mins = str_HR_PER_WEEK.substring(str_HR_PER_WEEK.indexOf('.') + 1);
var float_HR_PER_WEEK_mins = parseFloat("0." + (str_HR_PER_WEEK_mins), 10);
var float_HR_PER_WEEK_mins_actual = float_HR_PER_WEEK_mins * 60;
float_HR_PER_WEEK_mins_actual = float_HR_PER_WEEK_mins_actual.toString();
tables.CURRENT_EMPLOYEES.HOURS_PER_WEEK.value = getTwoDigitTime(str_HR_PER_WEEK_hrs) + ":" + getTwoDigitTime(float_HR_PER_WEEK_mins_actual);
}
else
{
tables.CURRENT_EMPLOYEES.HOURS_PER_WEEK.value = str_HR_PER_WEEK;
}
You have to ways to achieve that,
one, do the calculations yourself:
var decimalTimeString = "1.6578";
var decimalTime = parseFloat(decimalTimeString);
decimalTime = decimalTime * 60 * 60;
var hours = Math.floor((decimalTime / (60 * 60)));
decimalTime = decimalTime - (hours * 60 * 60);
var minutes = Math.floor((decimalTime / 60));
decimalTime = decimalTime - (minutes * 60);
var seconds = Math.round(decimalTime);
if(hours < 10)
{
hours = "0" + hours;
}
if(minutes < 10)
{
minutes = "0" + minutes;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
alert("" + hours + ":" + minutes + ":" + seconds);
Two, use built in function to convert to string and then to hh:mm:
var decimalTimeString = "1.6578";
var n = new Date(0,0);
n.setSeconds(+decimalTimeString * 60 * 60);
n.setMinutes(+decimalTimeString * 60);
var result = n.toTimeString().slice(0, 5);
document.write(result);
I've got a neat function to do just that:
function hoursToHHMM(hours) {
var h = String(Math.trunc(hours)).padStart(2, '0');
var m = String(Math.abs(Math.round((hours - h) * 60))).padStart(2, '0');
return h + ':' + m;
}
It handles negative values as a bonus.
Usage is trivial:
var hours = -7.33333;
console.log(hoursToHHMM(hours));
Results in: -07:20
You can play with it here: https://jsfiddle.net/r150c2me/
The below code prints the title of many cards and their countdown time.....the problem is that the timer is printed only for the first card. How do i print it for all the cards?I've tried a lot to search it on google but could find a relevant answer.Please help me on how to get timers on each card.
function previewall()
{
$.ajax({
type: "POST",
data: {
},
url: "readall.php",
dataType: "json",
success: function(JSONObject) {
var peopleHTML = "";
for (var key in JSONObject) {
if (JSONObject.hasOwnProperty(key)) {
peopleHTML += "<div class='wrapper'><label>" + JSONObject[key]["title"] + "</label><br>";
peopleHTML += "<p id='demo1'></p><br><p id=demo></p> </div>";
var x = setInterval(function() {
var count =JSONObject[key]["valid_date"];
var dat=JSONObject[key]["started_date"];
var countDownDate = new Date(count).getTime();
var date = new Date(dat).getTime();
// Get todays date and time
var now = new Date().getTime();
var elapsed = now - date;
var distance = countDownDate - now;
var planned= date - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var days1 = Math.floor(elapsed / (1000 * 60 * 60 * 24));
var hours1 = Math.floor((elapsed % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes1 = Math.floor((elapsed % (1000 * 60 * 60)) / (1000 * 60));
var seconds1 = Math.floor((elapsed % (1000 * 60)) / 1000);
var days2 = Math.floor(planned / (1000 * 60 * 60 * 24));
var hours2 = Math.floor((planned % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes2 = Math.floor((planned % (1000 * 60 * 60)) / (1000 * 60));
var seconds2 = Math.floor((planned % (1000 * 60)) / 1000);
if (distance < 0) {
document.getElementById("demo").innerHTML = "EXPIRED";
}
else if(elapsed<0){
document.getElementById("demo1").innerHTML = "Starts in " + days2 + "d " + hours2 + "h " + minutes2 + "m " + seconds2 + "s " ;
}
else
{
document.getElementById("demo1").innerHTML = "Posted <br>" + days1 + "d " + hours1 + "h " + minutes1 + "m " + seconds1 + "s ago" ;
document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s Left" ;
}
});
}
}
$("#people").html(peopleHTML);
}
});
}
The problem is that all timers bind the variable key, so when they fire, they see the final value of key.
Try this instead:
for (var k in JSONObject) {
let key = k;
if (JSONObject.hasOwnProperty(key)) {
...
You have multiple elements sharing the same id (i.e. demo, demo1), the resulting page is broken and this is the cause of the issue.
The fastest fix would be keeping a counter and embedding it in the various ids of the elements you create dinamically.
Something like:
var peopleHTML = "";
var i = -1;
for (var key in JSONObject) {
i++;
if (JSONObject.hasOwnProperty(key)) {
peopleHTML += "<div class='wrapper'><label>" + JSONObject[key]["title"] + "</label><br>";
peopleHTML += "<p id='demoOuter'"+i+"></p><br><p id=demoInner"+i+"></p> </div>";
// [CUT]
f (distance < 0) {
document.getElementById("demoInner"+i).innerHTML = "EXPIRED";
}
else if(elapsed<0){
document.getElementById("demoOuter"+i).innerHTML = "Starts in " + days2 + "d " + hours2 + "h " + minutes2 + "m " + seconds2 + "s " ;
}
else
{
document.getElementById("demoOuter"+i).innerHTML = "Posted <br>" + days1 + "d " + hours1 + "h " + minutes1 + "m " + seconds1 + "s ago" ;
document.getElementById("demoInner"+i).innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s Left" ;
}
My code is located below. I'm trying to set a countdown, however I can't figure out how to set the timer to operate. I've tried changing the "var setting". When I do it seems that the countdown works, however it glitches and the numbers appear but all go back to "0". Really confused. Someone Please help!
(function($) {
$.fn.countdown = function(options) {
var settings = { 'date': "30 september 2014 16:24:00" };
if(options) {
$.extend(settings, options);
}
this_sel = $(this);
function count_exec() {
eventDate = Date.parse(settings['date']) / 1000; // Parse the date string
currentDate = Math.floor($.now() / 1000); // Find the timestamp for now
seconds = eventDate - currentDate; // Find the number of seconds remaining
if (seconds <= 0) { // After the event date has passed
days = 0;
hours = 0;
minutes = 0;
seconds = 0;
} else {
days = Math.floor(seconds / (60 * 60 * 24)); // Divide to find the number of days remaining
seconds -= days * 60 * 60 * 24; // Subtract the number of (complete, => 24 hours) days calculated above
hours = Math.floor(seconds / (60 * 60)); // Get the number of hours from that modified number ^
seconds -= hours * 60 * 60;
minutes = Math.floor(seconds / 60);
seconds -= minutes * 60;
}
this_sel.find('#days').val(days).trigger('change');
this_sel.find('#hours').val(hours).trigger('change');
this_sel.find('#mins').val(minutes).trigger('change');
this_sel.find('#secs').val(seconds).trigger('change');
} // End of count_exec();
count_exec();
interval = setInterval(count_exec, 1000);
} // End of the main function
}) (jQuery);
Please but below code in your file and apply the desire date. It works fine for me. Let me know if any issue.
<body>
<form name="count">
<input type="text" size="69" name="count2">
</form>
<script type="text/javascript">
//change the text below to reflect your own,
var before = "Christmas!"
var current = "Today is Christmas. Merry Christmas!"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
function countdown(yr, m, d) {
theyear = yr; themonth = m; theday = d
var today = new Date()
var todayy = today.getYear()
if (todayy < 1000)
todayy += 1900
var todaym = today.getMonth()
var todayd = today.getDate()
var todayh = today.getHours()
var todaymin = today.getMinutes()
var todaysec = today.getSeconds()
var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec
futurestring = montharray[m - 1] + " " + d + ", " + yr
dd = Date.parse(futurestring) - Date.parse(todaystring)
dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1)
dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1)
dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1)
dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1)
if (dday == 0 && dhour == 0 && dmin == 0 && dsec == 1) {
document.forms.count.count2.value = current
return
}
else
document.forms.count.count2.value = "Only " + dday + " days, " + dhour + " hours, " + dmin + " minutes, and " + dsec + " seconds left until " + before
setTimeout("countdown(theyear,themonth,theday)", 1000)
}
//enter the Future count down date using the format year/month/day
countdown(2016, 9, 24)
</script>
</body>
I am building and auction site and a countdown timer is attached to each product.
i got a working script from here(stackoverflow) -> how to make countdown timer for bidding website
This is my code
<script>
var before = ""
var current = "Ended"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
jQuery.fn.countdown = function(yr, m, d) {
$that = $(this);
theyear = yr;
themonth = m;
theday = d;
var today = new Date();
var todayy = today.getYear();
if (todayy < 1000)
todayy += 1900;
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec
futurestring = montharray[m - 1] + " " + d + ", " + yr;
dd = Date.parse(futurestring) - Date.parse(todaystring);
dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
$that.val(current);
return;
}
else
$that.val(dday + "Days, " + dhour + ":" + dmin + ":" + dsec + before);
setTimeout(function() {
$that.countdown(theyear, themonth, theday);
}, 1000);
};
</script>
<input type="text" id="6" style="width: 900px">
<script>
$("#6").countdown(2011, 7, 27);
</script>
My Question is how can i add time to this? i am not so experienced in javascript to manipulate this to work with time
var before = ""
var current = "Ended"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
jQuery.fn.countdown = function (yr, m, d) {
$that = $(this);
var delta = 0;
var start = function (yr, m, d) {
theyear = yr;
themonth = m;
theday = d;
var today = new Date();
var todayy = today.getYear();
if (todayy < 1000) todayy += 1900;
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec
futurestring = montharray[m - 1] + " " + d + ", " + yr;
dd = Date.parse(futurestring) - Date.parse(todaystring) + delta;
dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
$that.val(current);
return;
} else $that.val(dday + "Days, " + dhour + ":" + dmin + ":" + dsec + before);
setTimeout(function () {
start(theyear, themonth, theday);
}, 1000);
}
return {
start: function () {
start(yr, m, d);
},
addTime: function (ms) {
delta += ms;
console.log(delta);
}
}
};
To use:
var cd = $("#6").countdown(2013, 7, 28);
cd.start();
cd.addTime(100000); //add time
FIDDLE
Got the solution
<script>
var before = ""
var current = "Ended"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
jQuery.fn.countdown = function(yr, m, d, h, min, s) {
$that = $(this);
theyear = yr;
themonth = m;
theday = d;
thehour = h;
theminute = min;
thesecond = s;
var today = new Date();
var todayy = today.getYear();
if (todayy < 1000)
todayy += 1900;
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
futurestring = montharray[m - 1] + " " + d + ", " + yr + " " + h + ":" + min + ":" + s;
//console.log(futurestring);
dd = Date.parse(futurestring) - Date.parse(todaystring);
dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
$that.text(current);
return;
}
else {
$that.text(dday + "Days " + dhour + ":" + dmin + ":" + dsec + before);
}
setTimeout(function() {
$that.countdown(theyear, themonth, theday, thehour, theminute, thesecond);
}, 1000);
};
</script>
<input type="text" id="6" style="width: 900px">
<script>
$("#6").countdown(2011, 7, 27, 12, 13, 12);
</script>