javascript日付の表現

608 ワード

function mydate(){ var time=new Date(); var year=time.getFullYear(); var hour=time.getHours(); var mon=time.getMonth()+1; var day=time.getDate(); var minu=time.getMinutes(); var sec=time.getSeconds(); hour=change(hour); minu=change(minu); sec=change(sec); document.getElementById("dat").innerHTML=year+"-"+mon+"-"+day+" "+hour+":"+minu+":"+sec; t=setTimeout("mydate()",500); } function change(num){ if(num<10){ return "0"+num; } else{ return num; } }