为毛我弄出来是00:00:00
var windowH=768;
var windowW=1024;
var radius=8;
var margin_top=60;
var margin_left=30;
var s=0;
const endTime=new Date(2016,9,5,15,22,54);
window.onload=function(){
var canvas=document.getElementById("canvas");
var context=canvas.getContext("2d");
// context.arc(100,100,80,0,1.5*Math.PI);
// context.strokeStyle="#f00";
// context.stroke();
canvas.width=windowW;
canvas.height=windowH;
render(context);
s=ss();
}
function ss(){
var curTime=new Date();
var ret=endTime.getTime()-curTime.getTime();
ret=Math.round(ret/1000);
return ret>=0 ? ret:0;
}
function render(cxt){
var hour=parseInt(s/3600);
var minutes=parseInt((s-hour*3600)/60);
var seconds=s%60;
renderDigit(margin_left,margin_top,parseInt(hour/10) ,cxt);
renderDigit(margin_left+15*(radius+1),margin_top,parseInt(hour%10) ,cxt);
renderDigit(margin_left+30*(radius+1),margin_top,10 ,cxt);
renderDigit(margin_left+39*(radius+1),margin_top,parseInt(minutes/10) ,cxt);
renderDigit(margin_left+54*(radius+1),margin_top,parseInt(minutes%10) ,cxt);
renderDigit(margin_left+69*(radius+1),margin_top,10 ,cxt);
renderDigit(margin_left+78*(radius+1),margin_top,parseInt(seconds/10) ,cxt);
renderDigit(margin_left+93*(radius+1),margin_top,parseInt(seconds%10) ,cxt);
}
function renderDigit(x,y,num,cxt){
cxt.fillStyle="rgb(0,102,153)";
for(var i=0;i<digit[num].length;i++){
for(var j=0;j<digit[num][i].length;j++){
if(digit[num][i][j]==1){
cxt.beginPath();
cxt.arc(x+j*2*(radius+1)+(radius+1),y+i*2*(radius+1)+(radius+1),radius,0,2*Math.PI);
cxt.closePath();
cxt.fill();
}
}
}
}
const endTime=new Date(2016,9,5,15,22,54);
时间设置的太长了,得设置成距离当前时间99小时以内
例如改成:const endTime=new Date(2016,8,3,15,22,54);这代表着2016年9月3号15时22分54秒
JavaScript的Date 的月份设置中 0代表1月,1代表2月,2代表3月。。。。11代表12月,12。。。报错;详情请参考javascriptAPI