<!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>js倒计时效果-精确到秒 </title>
<?php
//php的时间是以秒算。js的时间以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地区
//配置每天的活动时间段
$starttimestr = "2010-12-5 09:00:00";
$endtimestr = "2010-12-7 09:00:00";
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$lefttime = $endtime-$starttime; //实际剩下的时间(秒)
?>
<script language="JavaScript">
var overDate = <?php echo $lefttime;?>*1000;//截止时间
var NowTime = new Date();
var EndTime= new Date(NowTime.getTime() + overDate);
function GetRTime()
{
NowTime = new Date();
var nMS=EndTime.getTime() - NowTime.getTime();
var days=Math.floor(nMS/(1000*60*60*24));
var nH=Math.floor(nMS/(1000*60*60));
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
var nMS=Math.floor(nMS/100) % 10;
if(nH>= 0){
document.getElementById("RemainD").innerHTML=days;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS + "." + nMS;
}
else {
document.getElementById("CountMsg").innerHTML= "已过!";
}
}
setInterval("GetRTime()",100);
</script>
</head>
<body>
<div id="CountMsg">
<strong id="RemainD">XX</strong>天
<strong id="RemainH">XX</strong>时
<strong id="RemainM">XX</strong>分
<strong id="RemainS">XX</strong>秒
</div>
</body>
</html>
==============================
<!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>js倒计时效果-精确到秒 </title>
<?php
//php的时间是以秒算。js的时间以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地区
//配置每天的活动时间段
$starttimestr = "09:00:00";
$endtimestr = "21:58:35";
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
echo "活动还没开始,活动时间是:".$starttimestr."至".$endtimestr;
$lefttime = $endtime-$nowtime; //实际剩下的时间(秒)
?>
<script language="JavaScript">
//var overDate = 1000 * 60 * 60 * 24 * 3;//截止时间:为当前计算机时间+3天
var overDate = <?php echo $lefttime;?>*1000;//截止时间
var NowTime = new Date();
//var EndTime= new Date(2009,01,11,0,0);
var EndTime= new Date(NowTime.getTime() + overDate);
var EndTimeMsg = EndTime.getFullYear() + "年";
EndTimeMsg = EndTimeMsg + (EndTime.getMonth()+1) + "月";
EndTimeMsg = EndTimeMsg + (EndTime.getDate()) + "日";
EndTimeMsg = EndTimeMsg + (EndTime.getHours()) + "时";
EndTimeMsg = EndTimeMsg + (EndTime.getMinutes()) + "分";
EndTimeMsg = EndTimeMsg + (EndTime.getSeconds()) + "秒";
function GetRTime(){
NowTime = new Date();
var nMS=EndTime.getTime() - NowTime.getTime();
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;
var nMS=Math.floor(nMS/100) % 10;
if(nD>= 0){
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS + "." + nMS;
}
else {
document.getElementById("CountMsg").innerHTML= EndTimeMsg +"已过!";
}
setTimeout("GetRTime()",100);
}
window.onload=function(){
document.getElementById("EndTimeMsg").innerHTML = EndTimeMsg;
GetRTime();
}
</script>
</head>
<body>
<div id="CountMsg">
今天距离<strong id="EndTimeMsg">XX</strong><br />还有
<strong id="RemainD">XX</strong>天
<strong id="RemainH">XX</strong>时
<strong id="RemainM">XX</strong>分
<strong id="RemainS">XX</strong>秒
</div>
<hr />
<script language="JavaScript">
function ShowTimes(){
var AfterTime= new Date("6-20-2011");
LeaveTime = AfterTime - new Date();
LeaveDays=Math.floor(LeaveTime/(1000*60*60*24));//天
LeaveHours=Math.floor(LeaveTime/(1000*60*60)%24);//时
LeaveMinutes=Math.floor(LeaveTime/(1000*60)%60);//分
LeaveSeconds=Math.floor(LeaveTime/1000%60);//秒
LeaveMilliSeconds=Math.floor(LeaveTime/100%10);//秒
//var c=new Date();
//var q=AfterTime.getMilliseconds();
hxtime.innerHTML="<font color=red ><b>"+LeaveDays+"天</font> <font color=red>"+LeaveHours+"时</font> <font color=red>"+LeaveMinutes+"分</font> <font color=red>"+LeaveSeconds+"秒</font> <font color=red>"+LeaveMilliSeconds+"</font></b>";
}
setInterval(ShowTimes,10);
</script>
<div id="hxtime" style="padding-left:220px; margin:5px;color:#ffffff; font-size:18px;" ></div>
</body>
</html>
=====================================================================================
<?php
//php的时间是以秒算。js的时间以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地区
//配置每天的活动时间段
$starttimestr = "2010-12-5 09:00:00";
$endtimestr = "2010-12-5 09:00:12";
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$lefttime = $endtime-$starttime; //实际剩下的时间(秒)
?>
<script type="text/javascript">
var runtimes = 0;
function GetRTime()
{
var nMS = <?php echo $lefttime;?>*1000-runtimes*100;
var nH=Math.floor(nMS/(1000*60*60));
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
var nMS=Math.floor(nMS/100) % 10;
if(nH>= 0){
if(nH<10)nH="0"+nH;
if(nM<10)nM="0"+nM;
if(nS<10)nS="0"+nS;
if(nH==0 && nM==0 && nS<10){
var Str=nH+":"+nM+":"+nS+"."+nMS;
}else{
var Str=nH+":"+nM+":"+nS;
}
document.getElementById("AuctionTime").innerHTML=Str;
}
else {
document.getElementById("AuctionTime").innerHTML="00:00:00";
}
runtimes++;
}
setInterval("GetRTime()",100);
</script>
<div id="AuctionTime">--:--:--</div>
=====================================================================================
<!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>Jquery实现倒计时效果</title>
<script language="javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
SysSecond=11000;
InterValObj=window.setInterval(SetRemainTime,100);
});
function SetRemainTime(){
if(SysSecond>0){
SysSecond=SysSecond-100;
var hour=Math.floor(SysSecond/(1000*60*60));
var minite=Math.floor(SysSecond/(1000*60))%60;
var second=Math.floor(SysSecond/1000)%60;
var milliSecond=Math.floor(SysSecond/100)%10;
if(hour<10)hour="0"+hour;if(minite<10)minite="0"+minite;if(second<10)second="0"+second;
if(hour==0 && minite==0 && second<10){
$("#remainTime").html(hour+":"+minite+":"+second+":"+milliSecond);
}else{
$("#remainTime").html(hour+":"+minite+":"+second);
}
}else{
$("#remainTime").html("00:00:00");
window.clearInterval(InterValObj);
}
}
</script>
</head>
<body>
<div id="remainTime" style="font-size:20px;font-weight:800;color:#FF9900"></div>
</body>
</html>
=====================================================================================
<!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>Jquery实现倒计时效果</title>
<script language="javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var SysSecond;
var InterValObj;
$(document).ready(function(){
SysSecond = parseInt($("#remainSeconds").html()); //这里我是在服务端算好了剩余的秒数,并保存到客户端,如果过期则返回0
InterValObj = window.setInterval(SetRemainTime, 1000); //间隔函数,1秒执行
});
//代理,接单的时间+1小时减去当前时间的秒数
function SetRemainTime(){
if (SysSecond > 0) {
//alert(SysSecond);
SysSecond = SysSecond - 1;
var second = Math.floor(SysSecond % 60); // 计算秒
var minite = Math.floor((SysSecond / 60) % 60); //计算分
var hour = Math.floor((SysSecond / 3600) % 24); //计算小时
var day = Math.floor((SysSecond / 3600) / 24); //计算天
$("#remainTime").html(day + "天" + hour + "小时" + minite + "分" + second + "秒");
}else{//剩余时间小于或等于0的时候,就停止间隔函数
window.clearInterval(InterValObj);
}
}
</script>
<script language="javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var SysSecond;
var InterValObj;
$(document).ready(function(){
SysSecond=11000;//这里我是在服务端算好了剩余的秒数,并保存到客户端,如果过期则返回0
InterValObj=window.setInterval(SetRemainTime,100);//间隔函数,1秒执行
});
//代理,接单的时间+1小时减去当前时间的秒数
function SetRemainTime(){
if(SysSecond>0){
SysSecond=SysSecond-100;
var hour=Math.floor(SysSecond/(1000*60*60)); //计算小时
var minite=Math.floor(SysSecond/(1000*60))%60; //计算分
var second=Math.floor(SysSecond/1000)%60; //计算秒
var milliSecond=Math.floor(SysSecond/100)%10; //计算毫秒
if(hour<10)hour="0"+hour;if(minite<10)minite="0"+minite;if(second<10)second="0"+second;
if(hour==0 && minite==0 && second<10){
$("#remainTime").html(hour+":"+minite+":"+second+":"+milliSecond);
}else{
$("#remainTime").html(hour+":"+minite+":"+second);
}
}else{//剩余时间小于或等于0的时候,就停止间隔函数
$("#remainTime").html("00:00:00");
window.clearInterval(InterValObj);
}
}
</script>
</head>
<body>
<div id="remainSeconds" style="display:none">180000</div>
<div id="remainTime" style="font-size:20px;font-weight:800;color:#FF9900"></div>
</body>
</html>
|