//将格式为"yyyy-mm-dd hh:nn:ss"的时间字符串格式化,返回Js时间对象
function ParseDate(sDatetime)
{
var sTemp = sDatetime.replace(/[- :]/g, ", ");
var arrDatetime = sTemp.split(",");
var dtResult = new Date(arrDatetime[0], arrDatetime[1]-1, arrDatetime[2], arrDatetime[3], arrDatetime[4], arrDatetime[5]);
return dtResult;
}
//计算传入的时间与现在时间的差值,单位为秒
//传入时间早于现在时间的返回负值
function Seconds(objDate)
{
var dtCurTime = new Date();
var nResult = parseInt((objDate - dtCurTime) / 1000);
return nResult;
}
//倒计时钟
function CountDownClock(nSeconds)
{
document.getElementById("CountDownClock").innerHTML = FormatTimer(nSeconds);
nSeconds--; setTimeout("javascript:CountDownClock(" + nSeconds + ")", 1000);
}
//用于把倒计时钟显示的时间格式化为形如"00:00:00"的字符串
function FormatTimer(nSeconds)
{
var seconds = parseInt( nSeconds % 60 );
var minutes = parseInt( nSeconds / 60 % 60 );
var hours = parseInt( nSeconds / 60 / 60 ); if (seconds < 10) seconds = "0" + seconds;
if (minutes < 10) minutes = "0" + minutes;
if (hours < 10) hours = "0" + hours; var sResult = hours + ":" + minutes + ":" + seconds; return sResult;
}在页面定义一个id为"CountDownClock"的层就可以用了