You are here: irt.org | FAQ | JavaScript | date | Q1436 [ previous next ]
Try:
<script language="JavaScript"><!-- function timeTillDate(then) { now = new Date(); thenTime = then.getTime(); nowTime = now.getTime(); var difference = thenTime-nowTime; var daysDifference = Math.floor(difference/1000/60/60/24); difference = difference - daysDifference*1000*60*60*24; var hoursDifference = Math.floor(difference/1000/60/60); difference = difference - hoursDifference*1000*60*60 var secondsDifference = Math.floor(difference/1000); var string = ''; if (daysDifference > 0) { string += daysDifference + ' day'; if (daysDifference > 1) string +='s'; string += ' '; } if (hoursDifference > 0) { string += hoursDifference + ' hour'; if (hoursDifference > 1) string +='s'; string += ' '; } if (secondsDifference > 0) { string += secondsDifference + ' second'; if (secondsDifference > 1) string +='s'; string += ' '; } return string; } document.write(timeTillDate(new Date(3000,0,1))); //--></script>