日期:2014-05-16  浏览次数:20410 次

帮我个忙急着要,计时器
功能就是;给定一个日期。然后显示距今已过去的时间
比方说:

给定的是(2007-10-12 12:00:00) 至今已过去:5小时35分钟20秒

------解决方案--------------------
<script>
var d=new Date("2007","9","12","12");
var now=new Date();
var pass=parseInt((now.getTime()-d.getTime())/1000);
alert("已经过去"+parseInt(pass/60/60)+"小时"+parseInt(pass/60)%60+"分钟"+pass%60+"秒钟");
</script>
------解决方案--------------------
<script language=javascript>
var str="2007-10-11 15:00:00"
var re=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/
if(!re.test(str))
alert("输入错误")
var strYear=RegExp.$1;
var strMonth=RegExp.$2;
strMonth=parseInt(strMonth,10)-1
var strDate=RegExp.$3;
strDate=parseInt(strDate,10)
var strHour=RegExp.$4;
strHour=parseInt(strHour,10)
var strMinute=RegExp.$5;
strMinute=parseInt(strMinute,10)
var tempDate=new Date(strYear,strMonth,strDate,strHour,strMinute,0)
var nowDate=new Date()
var temp=parseInt((nowDate-tempDate)/1000)
var StrSeconds=temp%60
temp=parseInt(temp/60)
var strMinute=temp%60
temp=parseInt(temp/60)
var strHour=temp%24
temp=parseInt(temp/24)
document.write(temp+"天"+strHour+"小时"+strMinute+"分"+StrSeconds+"秒")
</script>
------解决方案--------------------
<div id="div1">&nbsp;</div>
 <script language=javascript >
var str="2007-10-11 15:00:00"
var re=/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/
if(!re.test(str))
alert("输入错误")
var strYear=RegExp.$1;
var strMonth=RegExp.$2;
strMonth=parseInt(strMonth,10)-1
var strDate=RegExp.$3;
strDate=parseInt(strDate,10)
var strHour=RegExp.$4;
strHour=parseInt(strHour,10)
var strMinute=RegExp.$5;
strMinute=parseInt(strMinute,10)
var tempDate=new Date(strYear,strMonth,strDate,strHour,strMinute,0)
function showDate(){
var nowDate=new Date()
var temp=parseInt((nowDate-tempDate)/1000)
var StrSeconds=temp%60
temp=parseInt(temp/60)
var strMinute=temp%60
temp=parseInt(temp/60)
var strHour=temp%24
temp=parseInt(temp/24)
document.getElementById("div1").innerText=(temp+"天"+strHour+"小时"+strMinute+"分"+StrSeconds+"秒")
setTimeout("showDate()",1000)
}
showDate()
</script >
------解决方案--------------------
<body><div id="dd"></div>
<script language="JavaScript">
<!--
function mm(strDate)
{
var d = Date.parse(strDate.replace(/-/g, "/"));
if(isNaN(d)){alert("date string is wrong!"); return;}
d = new Date().getTime() - d; var s="", n;
if((n=Math.floor(d/(1000*60*60*24)))>0) s += n +"日";
d %=(1000*60*60*24);
if((n=Math.floor(d/(1000*60*60)))>0) s += n +"时";
d %= (1000*60*60);
if((n=Math.floor(d/(1000*60)))>0) s += n +"分";
d %= (1000*60);
if((n=Math.floor(d/(1000)))>0) s += n +"秒";
return s;
}
setInterval(function(){document.getElementById("dd").innerHTML = mm("2007-10-11 12:00:00")}, 1000)
//-->
</script>