Loading...

자바스크립트

날짜를 입력하면 그날이 무슨 요일인지 출력

페이지 정보

작성자 관리자
작성일 2008.02.15 12:13
4,351 조회

본문

<html>
<head>
    <title></title>
<SCRIPT LANGUAGE="JavaScript">
<!--
var endM = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var months = new Array("1","2","3","4","5","6","7","8","9","10","11","12");
var days = new Array("일요일","월요일","화요일","수요일","목요일","금요일","토요일");
var type = new Array("과거","미래");

function timeCalculate() {
    var y = document.ymdForm1.year.value;
    var m = document.ymdForm1.month.options[document.ymdForm1.month.options.selectedIndex].value;
    var d = document.ymdForm1.day.options[document.ymdForm1.day.options.selectedIndex].value;
    var hlpr = endM[m];
        if (d < endM[m] + 1) {
        if (m == 1 && y % 4 == 0) { hlpr++; }
    var c = new Date(y,m,d);
    var dayOfWeek = c.getDay();
        document.ymdForm1.dw.value = days[dayOfWeek];
    if(c.getTime() > new Date().getTime()) {
        document.ymdForm1.time.value = type[1];
    }
    else {
        document.ymdForm1.time.value = type[0];
  }
}
    else {
        alert("입력하신 데이타 "+months[m]+" "+d+", "+y+" 부적합한 날짜입니다.");
  }
}

function setY() {
    var y = new Date().getYear();
        if (y < 2000) y += 1900;
            document.ymdForm1.year.value = y;
}
//-->
</script>
</head>

<BODY onLoad="setY()">         

<form name="ymdForm1">
<!--년-->
<input type="text" name="year" size="4">년
<!--달-->
<select name="month" size="1">
<option selected value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
<option value="3">4</option>
<option value="4">5</option>
<option value="5">6</option>
<option value="6">7</option>
<option value="7">8</option>
<option value="8">9</option>
<option value="9">10</option>
<option value="10">11</option>
<option value="11">12</option>
</select>월
<!--일-->
<select name="day" size="1">
<option selected value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>일 <br>
<input type="button" value="요일계산" name="gdi" onClick="timeCalculate()">
<input type="text" name="dw" size="5">
<input type="text" name="time" size="4"></p>
</form>
댓글 0
홈으로 전체메뉴 마이메뉴 새글/새댓글
전체 검색
회원가입