Hi All,

I have developed a application in jsp. I need to achieve a count down timer(days,hours,minutes,seconds) between from date to todate, considering below cases.

All below are assumed

(1) I have 4 product, for each product i have different end date stored in mysql in DB.

(2) I need to calculate time time remaining for the end date for each product, for eg;

Product 1 end date : 10/05/2010 (i need to show the time remaining for the end of 10/05/2010 from current time and date). Like wise i need to show for different products.

How to achieve this. Solutions for this would be highly appreciated. Thanks in advance.

Hi,
here's a short demo on how you would be able to show the time difference between the current date and target date.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Conent-Style-Type" content="text/css" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<title>Countdown Timer Demo</title>

<script type="text/javascript">

// <[CDATA[ 



var TIMER = function() {


   var now = new Date();

   var targetDate = new Date('May 9, 2010 5:25 pm'); // See the time difference between the current date up to the target 

date.

   var difference = targetDate - now;

   var milliseconds = Math.floor( difference % 1000);   
       difference = difference / 1000;
            
   var seconds = Math.floor( difference % 60 );
       difference = difference / 60;
   var minutes = Math.floor( difference % 60 );
       difference = difference / 60;

   var hours = Math.floor( difference % 24 );
       difference = difference / 24;
 
   var days = Math.floor( difference );
   
 
   var outStr = hours+ ' hours, ' + minutes;
	outStr += ' minutes, ' + seconds + ' seconds until the target date!'; 

  	 ( document.getElementById('countdown') || document.all.countdown ).innerHTML = outStr;
 
   setTimeout("TIMER()",1000);
}

onload = TIMER;

// ]]> 
 
</script>
	</head>
	<body>
<div id="countdown"></div>


	
	</body>
</html>

hope it helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.