js 实现简易时钟效果
大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪。江山如画,一时多少豪杰。遥想公瑾当年,小乔初嫁了,雄姿英发。羽扇纶巾,谈笑间,樯橹灰飞烟灭。故国神游,多情应笑我,早生华发。人生如梦,一尊还酹江月。--来自奔跑的panda部落,panda每天与您一起进步
<div id="time"></div> 3 <script> 4 time(); 5 setInterval(time,1000) 6 function time() { 7 var t = new Date(); 8 var y = t.getFullYear(), 9 m = t.getMonth() + 1, 10 d = t.getDate(), 11 h = t.getHours(), 12 min = t.getMinutes(), 13 s = t.getSeconds(); 14 if( y < 10 ){ y = \'0\' + y } 15 if( d < 10 ){ d = \'0\' + d } 16 if( h < 10 ){ h = \'0\' + h } 17 if( min < 10 ){ min = \'0\' + min } 18 if( s < 10 ){ s = \'0\' + s } 19 var full_time = y + \'-\' + m + \'-\' + d + \' \' + h + \':\' + min + \':\' + s; 20 document.getElementById(\'time\').innerText = full_time; 21 } 22 </script>