js获取时间
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="time"><span>当前时间:</span><div class="time" id="lclock"></div></div> </body> <script> function fortime() { var now=new Date(); var year=now.getFullYear(); var month=now.getMonth()+1; if(month<10){ month='0'+month }; var date=now.getDate(); if(date<10){ date='0'+date }; var hour=now.getHours(); if(hour<10){ hour='0'+hour }; var minute=now.getMinutes(); if (minute<10){ minute='0'+minute } ; var second=now.getSeconds(); if(second<10){ second='0'+second }; myclock=year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second lclock.innerHTML=myclock; setTimeout("fortime()",1000); } fortime(); </script> </html>