<HTML> <HEAD> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <SCRIPT LANGUAGE="JavaScript"> var now = new Date(); var nowDayOfWeek = now.getDay(); var nowDay = now.getDate(); var nowMonth = now.getMonth(); var nowYear = now.getYear(); nowYear += (nowYear < 2000) ? 1900 : 0; var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)); function formatDate(date) { var mymonth = date.getMonth()+1; var myweekday = date.getDate(); return (mymonth + "-" + myweekday); } function printWeek() { var sDate = formatDate(weekStartDate); var eDate = formatDate(weekEndDate); sDate = sDate.split("-"); if(sDate[1].length==1){sDate[1] = "0"+sDate[1];} eDate = eDate.split("-"); if(eDate[1].length==1){eDate[1] = "0"+eDate[1];} sDate = sDate[0]+"-"+sDate[1]; eDate = eDate[0]+"-"+eDate[1]; $("#sDate").val(nowYear+"-"+sDate); $("#eDate").val(nowYear+"-"+eDate); } function printMonth(){ var sDate = new Date(nowYear, nowMonth); var eDate = new Date(now.getYear(), now.getMonth()+1,0); sDate = formatDate(sDate); eDate = formatDate(eDate);
sDate = sDate.split("-"); if(sDate[1].length==1){sDate[1] = "0"+sDate[1];} eDate = eDate.split("-"); if(eDate[1].length==1){eDate[1] = "0"+eDate[1];} sDate = sDate[0]+"-"+sDate[1]; eDate = eDate[0]+"-"+eDate[1]; $("#sDate").val(nowYear+"-"+sDate); $("#eDate").val(nowYear+"-"+eDate); } </script> <!------- 여기까지 ----->
<BODY><style> body,td {font-size:12px} </style>
</HEAD><input type="text" id="sDate"> - <input type="text" id="eDate"> <input type="button" onclick="printWeek();" value="금주"> <input type="button" onclick="printMonth();" value="금월"> </BODY>
</HTML>
''.' Programs > JavaScript' 카테고리의 다른 글
크롬, 파이어폭스, 익스플로러 호환 자동 리사이즈 아이프레임(iframe) (0) | 2013.09.10 |
---|---|
javascript 로 PC에서 접속했는지 모바일 기기에서 접속했는지 체크하기 (0) | 2013.06.11 |
innerHTML VS jQuery html VS jQuery append 함수 처리 속도는? (1) | 2012.09.25 |
[레이어] 스크롤에 상관없이 화면 가운데 높이 가운데 출력. (0) | 2012.07.09 |
[JS] PHP 변수 처리 시 참고 사항. (0) | 2012.05.04 |