Recent posts

Recent comments

Archive

Calender

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

출력 결과


소스 코드

<p id="realTimer"></p>

<script type="text/javascript">

function timer(){ 

	 var date = new Date(); 

	 // 그 지역의 날짜 (locale date). 
	 var dateString = date .toLocaleDateString(); 

	 // 그 지역의 시간 (locale time). 
	 var timeString = date .toLocaleTimeString(); 

	 var text = dateString + " " + timeString; 

	 // 'text'만 저장하고, 이 함수 끝내기. 
	 return text; 
} 


function get_timer(){ 

	 // 함수값 불러와서, 태그 안에 집어넣기. 
	 document.getElementById( "realTimer" ).innerHTML = timer(); 

	 // 1000 밀리초(=1초) 후에, 이 함수를 실행하기 (반복 실행 효과). 
	 setTimeout( "get_timer()", 1000 ); 
}


// (페이지가 열리자마자) 함수를 불러오기. 
var callFunction = get_timer(); 

</script>
 


이 블로그에서 함께 볼만한 글.

2. [JavaScript] 오늘 날짜와 현재 시각 ─ Date()




이 내용이 도움이 되셨나요? *^^*