直接贴demo吧!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
//php的时间是以秒算。js的时间以毫秒算
date_default_timezone_set('PRC');
//date_default_timezone_set("Asia/Hong_Kong");//地区
//配置每天的活动时间段
$starttimestr = "2015-8-5 9:33:00";
$endtimestr = "2017-9-13";
?>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">
var starttime=<?php echo strtotime($starttimestr); ?>;
var endtime=<?php echo strtotime($endtimestr);?>;
var nowtime=<?php echo time();?>;
var lefttime=0;
var runtimes = 0;
var Num = 0;
var nS=0;
function GetRTime(){
var nMS = lefttime*1000-runtimes*1000;
if (nMS>=0){
var nD=Math.floor(nMS/(1000*60*60*24));
var nH=Math.floor(nMS/(1000*60*60))%24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS;
if(nS ==0 && nM==0 && nH==0 && nD ==0){
if(window.name==""){
parent.location.reload();
window.name = "0";
}
else{
if(window.name=="0"){
parent.location.reload();
window.name = eval(window.name) + 1;
}
else{
}
}
}
runtimes++;
setTimeout("GetRTime()",1000);
}
}
$(function(){
if(nowtime<starttime){
$('#titile').text('距离活动开始');
window.name = "";
lefttime=starttime-nowtime;
}else if(endtime>nowtime && nowtime>starttime){
$('#titile').text('距离活动结束');
window.name=="0"
lefttime=endtime-nowtime;
}else{
window.name = "1";
$('#titile').text('活动已经结束');
}
GetRTime();
})
</script>
<h4><span id="titile"> </span><strong id="RemainD">XX</strong>天 <strong id="RemainH">XX</strong>小时 <strong id="RemainM">XX</strong>分钟 <strong id="RemainS">XX</strong>秒</h4>
</body>
</html>