...

View Full Version : how to: time date etc...



narf
12-20-2003, 08:09 PM
i have been having trouble in the past trying to make pges that use the date. Say for instance, count down to christmas in seconds hours and days.

could you tell me how to get the date into a var and then take that away from the date of christmas.

and would i need to put the seconds hours days months and years in seperate vars.


thanks:thumbsup:

COBOLdinosaur
12-20-2003, 09:17 PM
Try this:

<html>
<head><title>none</title>
<script type="text/javascript">
<!--
var xmas= new Date(2003,11,25,0,0,0);
function setCountdown() {
var now= new Date();
var diff=xmas.valueOf()-now.valueOf();
diff=parseInt(diff/1000);
days=parseInt(diff/86400);
diff-=days*86400;
hours=parseInt(diff/3600);
diff-=hours*3600;
minutes=parseInt(diff/60);
diff-=minutes*60;
str=days+" days "+hours+" hours "+minutes+" minutes and "+diff+" seconds to Christmas";
document.getElementById('countdown').innerHTML=str;
setTimeout('setCountdown()',1000);
}
//-->
</script>
</head>
<body onLoad="setCountdown()">
<div id="countdown" style="width:400px;border:4px double blue;text-align:center;">
&nbsp;</div>
</body>
</html>


You can put each part in its own var if you want and you can put it in to a form field, or just about any element or control that will accept a string.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum