html 페이지에 년 월 일 시 분 초 와 요일 을 표시하는 두 가지 방식

2607 단어
Js 코드
//----------------------------- ---------------------------------------------


<br>function startTime(){ <br>var today=new Date(); <br>var strDate=(" "+today.getYear()+" "+(today.getMonth()+1)+" "+today.getDate()+" "); <br>var n_day=today.getDay(); <br>switch(n_day){ <br>case 0: <br>{strDate=strDate+" "}break; <br>case 1: <br>{strDate=strDate+" "}break; <br>case 2: <br>{strDate=strDate+" "}break; <br>case 3: <br>{strDate=strDate+" "}break; <br>case 4: <br>{strDate=strDate+" "}break; <br>case 5: <br>{strDate=strDate+" "}break; <br>case 6: <br>{strDate=strDate+" "}break; <br>case 7: <br>{strDate=strDate+" "}break; <br>} <br>// <br>// add a zero in front of numbers<10 <br>var h=today.getHours(); <br>var m=today.getMinutes(); <br>var s=today.getSeconds() <br>m=checkTime(m); <br>s=checkTime(s); <br>strDate=strDate+" "+h+":"+m+":"+s; <br>document.getElementById('txt').innerHTML=strDate; <br>t=setTimeout('startTime()',500) <br>} <br> <br>function checkTime(i){ <br>if (i<10) {i="0" + i} <br>return i <br>} <br>







//-------------------------------- -----------------------------------------


<br>var today=new Date(); <br>var strDate=(" "+today.getYear()+" "+(today.getMonth()+1)+" "+today.getDate()+" "); <br>var n_day=today.getDay(); <br>switch(n_day){ <br>case 0: <br>{strDate=strDate+" "}break; <br>case 1: <br>{strDate=strDate+" "}break; <br>case 2: <br>{strDate=strDate+" "}break; <br>case 3: <br>{strDate=strDate+" "}break; <br>case 4: <br>{strDate=strDate+" "}break; <br>case 5: <br>{strDate=strDate+" "}break; <br>case 6: <br>{strDate=strDate+" "}break; <br>case 7: <br>{strDate=strDate+" "}break; <br>} <br>document.write(strDate); <br>

좋은 웹페이지 즐겨찾기