본문 바로가기
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"> 

var today = new Date(); //사용자 컴퓨터의 현재 시간과 날짜를 변수 today에 저장 
 
var year = today.getYear(); //년도 값을 얻음
if (year < 2000){year += 1900;} //Y2K문제를 해결하기 위해 사용
 
var month = today.getMonth()+1//월 값을 얻음
 
var date = today.getDate(); //일 값을 얻음
 
var day = today.getDay(); //요일 값을 얻음
 
//숫자로 된 요일 값을 문자로 변경하기 위해 사용
var week; 
if (day == 0) {week = "일요일";}
else if (day == 1) {week = "월요일";}
else if (day == 2) {week = "화요일";}
else if (day == 3) {week = "수요일";}
else if (day == 4) {week = "목요일";}
else if (day == 5) {week = "금요일";}
else if (day == 6) {week = "토요일";}
 
var hour = today.getHours(); //시간 값을 얻음 
 
//오전과 오후를 구별하기 위해 사용
if(hour>12){hour="오후 "+(hour-12);}
else{hour="오전 "+hour;}
 
var minute = today.getMinutes(); //분 값을 얻음
 
var second = today.getSeconds(); //초 값을 얻음
 
var mytime = '오늘은 '+year+'년 '+month+'월 '+date+'일 '+week+'입니다.<BR>';
mytime += '현재 시간은 '+hour+'시 '+minute+'분 '+second+'초입니다.';

</SCRIPT> 
</HEAD>
<BODY BGCOLOR="black"> 
<TABLE WIDTH="100%" HEIGHT="100%"> 
<TR><TD VALIGN="top">
<SCRIPT LANGUAGE="JavaScript"> 

document.write("<FONT COLOR=\"white\">"+mytime+"</FONT>");

</SCRIPT>
</TD></TR>
<TR><TD ALIGN="center" VALIGN="middle">
<A HREF="#" onfocus="this.blur()"><IMG SRC="dot.jpg" BORDER="0"></A>
</TD></TR>
</TABLE>
</BODY>
</HTML>
 
 
cs



728x90
반응형