환영합니다
※현재 시각은 입니다.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>환영합니다</h1>
현재 시각은 <input type="text" size="20" id="timebox"> 입니다.
<script type="text/javascript">
function nowtime() {
let now = new Date();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
if(hour < 10){
hour = "0" + hour;
}else if(minute < 10){
minute = "0" + minute;
}else if(second < 10){
second = "0" + second;
}
document.getElementById("timebox").value = hour + ":" + minute + ":" + second;
}
setInterval("nowtime()", 1000);
</script>
</body>
</html>
10 미만 숫자 앞에 0을 붙혀줬을 경우
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>환영합니다</h1>
※현재 시각은 <input type="text" id="date" size="10">입니다.<br>
<script type="text/javascript">
function datas() {
let dates = new Date();
document.getElementById("date").value =
dates.getHours()+":"+
dates.getMinutes()+":"+
dates.getSeconds();
}
setInterval("datas()", 1000);
</script>
</body>
</html>