How Many Days Until Christmas
/*
JavaScript Bible, Fourth Edition
by Danny Goodman
John Wiley & Sons CopyRight 2001
*/
<HTML>
<HEAD>
<TITLE>Christmas Countdown</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getDaysUntilXmas() {
var oneMinute = 60 * 1000
var oneHour = oneMinute * 60
var oneDay = oneHour * 24
var today = new Date()
var nextXmas = new Date()
nextXmas.setMonth(11)
nextXmas.setDate(25)
if (today.getMonth() == 11 && today.getDate() > 25) {
nextXmas.setFullYear(nextXmas.getFullYear() + 1)
}
var diff = nextXmas.getTime() - today.getTime()
diff = Math.floor(diff/oneDay)
return diff
}
</SCRIPT>
</HEAD>
<BODY>
<H1>
<SCRIPT LANGUAGE="JavaScript">
var header = "You have <I>" + getDaysUntilXmas() + "</I> "
header += "shopping days until Christmas."
document.write(header)
</SCRIPT>
</H1><HR>
</BODY>
</HTML>
Related examples in the same category