Menu

달력및 시간

2016. 6. 1. 20:07

안개핑 Javascript

 

 

<table cellpadding=0 border="0" width="450" align="center">
<tr>
<td width="20">
<p> </p>
</td>
<td width="430" bgcolor="#cccc99">
<p><SCRIPT LANGUAGE="JavaScript">

 

setCal()

function getTime()

{

var now = new Date()

var hour = now.getHours()

var minute = now.getMinutes()

now = null

var ampm = ""

if (hour >= 12)

{

hour -= 12

ampm = "PM"

}

else

ampm = "AM"

hour = (hour == 0) ? 12 : hour

 

if (minute < 10)

minute = "0" + minute

return hour + ":" + minute + " " + ampm

}

 

function leapYear(year)

{

if (year % 4 == 0)

return true

/* else */

return false

}

 

function getDays(month, year)

{

var ar = new Array(12)

ar[0] = 31

ar[1] = (leapYear(year)) ? 29 : 28

ar[2] = 31

ar[3] = 30

ar[4] = 31

ar[5] = 30

ar[6] = 31

ar[7] = 31

ar[8] = 30

ar[9] = 31

ar[10] = 30

ar[11] = 31

return ar[month]

}

 

function getMonthName(month)

{

var ar = new Array(12)

ar[0] = "January"

ar[1] = "February"

 

ar[2] = "March"

ar[3] = "April"

ar[4] = "May"

ar[5] = "June"

ar[6] = "July"

ar[7] = "August"

ar[8] = "September"

ar[9] = "October"

ar[10] = "November"

ar[11] = "December"

return ar[month]

}

 

function setCal()

{

var now = new Date()

var year = now.getYear()

var month = now.getMonth()

var monthName = getMonthName(month)

var date = now.getDate()

now = null

var firstDayInstance = new Date(year, month, 1)

var firstDay = firstDayInstance.getDay()

firstDayInstance = null

var days = getDays(month, year)

drawCal(firstDay + 1, days, date, monthName, + year)

}

 

function drawCal(firstDay, lastDate, date, monthName, year)

{

var headerHeight = 50

var border = 10

var cellspacing = 2

var headerColor = "#ce9e63"

var headerSize = "+3"

var colWidth = 60

var dayCellHeight = 25

var dayColor = "#ce9e63"

var cellHeight = 40

var todayColor = "#ce6163"

var timeColor = "red"

var text = ""

 

 

text += '<CENTER>'

text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>'

text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>'

text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>'

text += monthName + ' ' + year

text += '</FONT>'

text += '</TH>'

var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'

openCol += '<FONT COLOR="' + dayColor + '">'

var closeCol = '</FONT></TD>'

var weekDay = new Array(7)

weekDay[0] = "SUN"

weekDay[1] = "MON"

weekDay[2] = "TUE"

weekDay[3] = "WED"

weekDay[4] = "THU"

weekDay[5] = "FRI"

weekDay[6] = "SAT"

text += '<TR ALIGN="center" VALIGN="center">'

for (var dayNum = 0; dayNum < 7; ++dayNum)

{

text += openCol + weekDay[dayNum] + closeCol

}

text += '</TR>'

var digit = 1

var curCell = 1

 

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row)

{

text += '<TR ALIGN="center" VALIGN="top">'

for (var col = 1; col <= 7; ++col)

{

if (digit > lastDate)

break

if (curCell < firstDay)

{

text += '<TD></TD>';

curCell++

}

else

{

if (digit == date)

{

text += '<TD HEIGHT=' + cellHeight + '>'

text += '<FONT COLOR="' + todayColor + '">'

text += digit

text += '</FONT><BR>'

text += '<FONT COLOR="' + timeColor + '" SIZE=2>'

text += '<CENTER>' + getTime() + '</CENTER>'

text += '</FONT>'

text += '</TD>'

}

else

text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'

digit++

}

}

text += '</TR>'

}

text += '</TABLE>'

text += '</CENTER>'

document.write(text)

}

</SCRIPT>
</td></tr></table>