方法 1
<script language="javascript" type="text/javascript"> function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式 var aDate, oDate1, oDate2, iDays aDate = sDate1.split("-") oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]+" 01:00:00") //转换为12-18-2002格式 aDate = sDate2.split("-") oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]+" 00:00:00") alert(oDate2); iDays = parseInt(Math.floor(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数 return iDays } var timenow = "2008-11-14" var bb = DateDiff("2008-11-15", timenow); alert(bb); </script> <script language=javascript>
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]+" 01:00:00") //转换为12-18-2002格式
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]+" 00:00:00")
alert(oDate2);
iDays = parseInt(Math.floor(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
return iDays
}
var timenow = "2008-11-14"
var bb = DateDiff("2008-11-15", timenow);
alert(bb);
</script>
方法 2
<script language="JavaScript">
var DifferenceHour = -1;
var Tday = new Date("Novem 15, 2008 00:00:00"); //**倒计时时间点-注意格式
var daysms = 24 * 60 * 60 * 1000;
function clock()
{
var returnStr = "";
var time = new Date();
var Diffms = Tday.getTime() - time.getTime();
DifferenceHour = Math.floor(Diffms / daysms);
var dayStr = DifferenceHour.toString();
var ss = dayStr.split("");
for(q=0;q<ss.length;q++)
{ if(ss[q]=='-')
{
returnStr = "已过期";
break;
}
returnStr = returnStr+"<img src=images/"+ss[q]+".png border='0' height='23px' />";
}
document.getElementById("xx").innerHTML=returnStr;
}
</script>
<script language="JavaScript" type="text/javascript"> var DifferenceHour = -1; var Tday = new Date("Novem 15, 2008 00:00:00"); //**倒计时时间点-注意格式 var daysms = 24 * 60 * 60 * 1000; function clock() { var returnStr = ""; var time = new Date(); var Diffms = Tday.getTime() - time.getTime(); DifferenceHour = Math.floor(Diffms / daysms); var dayStr = DifferenceHour.toString(); var ss = dayStr.split(""); for(q=0;q "; } document.getElementById("xx").innerHTML=returnStr; } </script>