试图计算 08/28/2011 和当前日期之间的天数。出于某种原因, document.write 行没有做任何事情。
<script type="text/javascript">
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2011,08,28);
var secondDate = new Date(year,month,day);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
document.write(diffdays);
</script>