用js实现时间效果

</pre><pre code_snippet_id="1639839" snippet_file_name="blog_20160409_2_7614637" name="code" class="javascript"><pre name="code" class="javascript">function format(num){
if(num<10){
	num="0"+num;
}

return num;
}
//输出当前的年月日、星期几和时间
 div1=document.getElementById("div1");
div1.innerHTML=showTime();
t=setTimeout(showTime,500);
function showTime(){
clearTimeout(t);
var getD=new Array();
getD[0]="星期日";
getD[1]="星期一";
getD[2]="星期二";
getD[3]="星期三";
getD[4]="星期四";
getD[5]="星期五";
getD[6]="星期六";
var date=new Date();
var dateY=date.getFullYear();
var dateM=date.getMonth()+1;
var dateD=date.getDate();
var dateT=date.getDay();
var dateH=date.getHours();
var dateMs=date.getMinutes();
var dateS=date.getSeconds();
return (dateY+"年"+dateM+"月"+dateD+"日"+getD[dateT]+""+format(dateH)+":"+format(dateMs)+":"+format(dateS));
t=setTimeout(showTime,500);
}
//输出距离指定日期的天数(倒计时)
function leftTime(){
	var now=new Date();
	var deadline=new Date(2016,5,6);
	var lefttime=deadline.getTime()-now.getTime();
	return Math.ceil(lefttime/(24*60*60*1000));

}


 
 

你可能感兴趣的:(JavaScript,时间输出)