The following code is configured to count days until (or from) August 8th, 2008. Because 8 is an auspicious number in Chinese culture, this day was chosen for the opening ceremonies of the 2008 Summer Olympics in Beijing.
// set countdown time in milliseconds
// put desired day as arguments to Date.UTC
// in the order:
// year, month (remember January is 0), day of month, offset from GMT
// NOTE: we are using the offset because that represents midnight
// (beginning of the day) in a specific timezone
// get the current time and convert to milliseconds
var now=new Date();
var day_cnt= Math.ceil(( countdown_time - now_millisecs)/86400000 )
// display the number of days left (or since)
if ( day_cnt > 1 )
// multiple days to go
document.write( day_cnt + " days to go")
else if ( day_cnt == 1 )
// one day to go
document.write( day_cnt + " day to go")
else if ( day_cnt == 0 )
// it's today
else if ( day_cnt == -1 )
// one day ago
document.write( day_cnt + " day ago")
// multiple days ago
document.write( day_cnt + " days ago")
This site needs an editor - click to learn more!
You Should Also Read:
Introduction To UTC Dates
Editor's Picks Articles
Top Ten Articles
Content copyright © 2022 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.