본문 바로가기
Developer/Javascript & jQuery

[Javascript] 동적 현재시간

by 순수한소년 2017. 1. 29.
728x90
반응형
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
<HTML>
<HEAD></HEAD>
<BODY bgcolor="#ffccff">
<center><br><br>
<FORM NAME="myform">
<INPUT TYPE="text" NAME="mytext">
</FORM>
</center>
<SCRIPT LANGUAGE="JavaScript"> 
 
function showTime(){
var today = new Date();
var hour = today.getHours(); 
if(hour>12){hour="오후 "+(hour-12)}
else{hour="오전 "+hour}
var minute = today.getMinutes();
if(minute<10){minute="0"+minute;}
var second = today.getSeconds();
if(second<10){second="0"+second;}
var mytime = hour+':'+minute+':'+second;
document.myform.mytext.value = mytime;
}
setInterval("showTime()",1000);
 
</SCRIPT> 
</BODY>
</HTML>
cs




728x90
반응형