Daily coding

Java Script : 예제5 - 현재 시간 출력하기 본문

Front-end/Java Script

Java Script : 예제5 - 현재 시간 출력하기

sunnnkim 2020. 1. 9. 19:47

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>환영합니다</h1>
※ 현재시각은 <input type="text" size="10" id="time">입니다.

<script type="text/javascript">
setInterval("mytime()", 1000);
function mytime(){
	var now = new Date();
	var hour = now.getHours() % 13 ;
	var minute = now.getMinutes()<10? "0"+now.getMinutes():now.getMinutes();
	var strTime = 
		hour + ":" + 
		now.getMinutes() + ":" +
		now.getSeconds();

	document.getElementById("time").value = strTime;	

}
</script>

</body>
</html>