js解决
$("body").prepend('<canvas id="canvas" style="position:absolute;z-index:10;left: 0.3%;top:0.5%;" width="240" height="25"></canvas>');
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.strokeStyle = 'white';
function renderTime() {
var date=new Date();
var year=date.getFullYear(); //获取当前年份
var mon=date.getMonth()+1; //获取当前月份
var da=date.getDate(); //获取当前日
if(mon < 10) {
mon = "0" + mon;
}
if(da < 10) {
da = "0" + da;
}
var hh=date.getHours(); //获取小时
var mm=date.getMinutes(); //获取分钟
var ss=date.getSeconds(); //获取秒
if(hh < 10) {
hh = "0" + hh;
}
if(mm < 10) {
mm = "0" + mm;
}
if(ss < 10) {
ss = "0" + ss;
}
if(ss !=0){
clear();//清空一下画布
}
var d=year + '-' + mon + '-' + da + ' ' + hh + ':' + mm + ':' + ss;
ctx.globalAlpha=0.9;
ctx.font = "bold 16pt Asia";
ctx.fillStyle = '#f6d460';//字体色
ctx.textAlign="center";
ctx.fillText(d, 120, 20);
}
setInterval(renderTime, 40);
function clear(){
ctx.clearRect(0,0, 240, 40);
}