网站代码(时间倒记时)

来源:百度知道 编辑:UC知道 时间:2024/05/11 01:36:24
<script language="JavaScript" type="text/javascript">
function time1()
{
now=new Date();
m=now.getMonth();
n=now.getYear()
a=2009-now.getYear();
b=01-now.getMonth();
if(m=1,3,5,7,8,10,12){c=31-now.getDate()}
if(m=4,6,9){c=30-now.getDate()}
if(m=2){c=28-now.getDate()}
if(n=2004,2007){c=15-now.getDate()}
e="0"+24-now.getHours();
f="0"+59-now.getMinutes();
g="0"+60-now.getSeconds();
if(e>10){e=24-now.getHours()}
if(f>10){f=59-now.getMinutes()}
if(g>10){g=60-now.getSeconds()}
document.getElementById("d").innerHTML="本网站到期时间还有"+a+"年"+b+"个月"+c+"天"+e+"小时"+f+"分"+g+"秒"
}
setInterval('time1()',1000)
</script>
<span id="d">本网站到期时间还有1年1个月-16天5小时35分10秒</span></p>

时间是上这样的
购买日期: 2008-1-25 19:15

好了,为你量身定做的:

<span id="d">本网站到期时间还有1年1个月-16天5小时35分10秒</span>
<script type="text/javascript">
function getTimeStr(dt,flg){
var a,b,c,d,cy=cd=ch=cm=cs=0;
d=Date.parse(dt);
b=(new Date()).getTime();
a=Math.floor((d-b)/1000);
if(flg&&a<0)return "时间已经过期了";
cs=a%60;
c=Math.floor(a/60);
if(c>0){
cm=c%60;
c=Math.floor(c/60);
}
if(c>0){
ch=c%24;
c=Math.floor(c/24);
}
if(c>0){
cd=c%365;
cy=Math.floor(c/365);
}
if(cs<10)cs='0'+cs;
if(cm<10)cm='0'+cm;
if(ch<10)ch='0'+ch;
return cy+'年'+cd+'天'+ch+'时'+cm+'分'+cs+'秒';
}

function showTime(){
document.getElementById("d").innerHTML='本网站到期时间还有'+getTimeStr("2009/1/25 19:08:13");
}

setInterval(showT