본문 바로가기
프로그래밍/html & jsp

오늘 날짜 시간까지 나오는 자바스크립트

by Super User 2009. 6. 10.

<!--1. 아래의 스크립트를 원하는 위치에 넣으세요.^^ -->
<SCRIPT language="JavaScript">
<!--
 var today = new Date();
 document.write(today.getYear()+ "년 ");
 document.write((today.getMonth()+ 1) + "월");
 document.write(today.getDate()+ "일 ");
 document.write(today.getHours()+"시 ");
 document.write(today.getMinutes()+ "분 ");
 document.write(today.getSeconds()+ "초 ");
 //-->
 </SCRIPT>

 

 

결과는

2006년 5월2일 17시 9분 35초

 

빨갱이반장을 참조글 :

 

getYear(), getMonth(), getDate(), getHours(), getMiinutes() getSeconds() 함수기 때문에 외우시구요

 

단 년,달,월,일,시,분,초 맨앞에 영문자는 항상 대문자로 해야합니다.

 

또 getMonth() +1 이 있는 왜 해주어야 하는냐면 +1일 하지 않으면 0월달로 인식이 되기 때문입니다. 그래서 +1일 해주어야 합니다.

 

PhP로 그렇게 된다고 하시네요 샌님께서 참조하세요..

 

두번째 응용한 시간날짜자바스크립트

 

 

<!--1. 아래의 스크립트를 원하는 위치에 넣으세요.^^ -->
<SCRIPT LANGAGE="JavaScript">
<!--
 var today = new Date();
 document.write("<font size=5 color=red> <b> 오늘날짜는" + today.getYear()+ "년 ");
 document.write((today.getMonth()+ 1) + "월");
 document.write(today.getDate()+ "일, <br> 현재 시각은 ");
 document.write(today.getHours()+ "시");
 document.write(today.getMinutes()+ "분 ");
 document.write(today.getSeconds()+ "초입니다. </b> </font>");
 
// -->
</SCRIPT>

 

결과는

 

오늘날짜는2006년 5월2일,
현재 시각은 17시23분 38초입니다.