<script>
window.onload=function(){
showTime();
}
function checkTime(i){
if(i<10){
i="0"+i;
}
return i;
}
function showTime(){
var myDate = new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth()+1;
var day=myDate.getDate();
var h=myDate.getHours();
var m=myDate.getMinutes();
var s=myDate.getSeconds();
m=checkTime(m);
s=checkTime(s);
var weekday=new Array(7);
weekday[0]="星期日";
weekday[1]="星期一";
weekday[2]="星期二";
weekday[3]="星期三";
weekday[4]="星期四";
weekday[5]="星期五";
weekday[6]="星期六";
document.getElementsByClassName('showtimer')[0].innerHTML=year+'年'+month+'月'+day+'日'+weekday[myDate.getDay()]+h+':'+m+':'+s;
setTimeout(showTime,500);
}
高考倒计时
<script type="text/javascript">
window.onload=function(){
var currenttime=new Date();
var endtime=new Date("2019/6/23");
var lasttime=Math.ceil((endtime.getTime()-currenttime.getTime())/(24*60*60*1000));
document.getElementsByClassName('lefttime')[0].innerHTML +=lasttime;
}
</script>
限时抢
<script>
window.onload=function(){
showTime();
}
function checkTime(i){
if(i<10){
i="0"+i
}
return i;
}
function showTime(){
var startime=new Date();
var endtime=new Date("2018/10/10/,08:45:12");
var lasttime=parseInt((endtime.getTime()-startime.getTime())/1000);
var d=parseInt(lasttime/(24*60*60));
var h=parseInt(lasttime/(60*60)%24);
var m=parseInt(lasttime/60%60);
var s=parseInt(lasttime%60);
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
document.getElementsByClassName('lefttime')[0].innerHTML=d+'天'+h+'小时'+m+'分'+s+'秒';
setTimeout(showTime,1);
if(lasttime<=0){
document.getElementsByClassName('lefttime')[0].innerHTML='团购已结束';
}
}
</script>