250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Thymeleaf
- jpa
- oracle
- STS
- myBatis
- AJAX
- git
- Source
- Eclipse
- Python
- Spring Boot
- 문서
- 설정
- Tomcat
- MSSQL
- spring
- MySQL
- IntelliJ
- error
- JDBC
- maven
- Open Source
- Exception
- Docker
- ubuntu
- PostgreSQL
- 오픈소스
- Core Java
- JavaScript
- SpringBoot
Archives
- Today
- Total
헤르메스 LIFE
[Javascript] 날짜 오늘, 이번주, 이번달 본문
728x90
<input type= 'button' value ='오늘' onclick="DateSearch.getToday();" > <input type= 'button' value ='이번주' onclick ="DateSearch.getThisWeek();"> <input type= 'button' value ='이번달' onclick ="DateSearch.getThisMonth();"> <input type= 'button' value ='전체' onclick="DateSearch.resetDate();" > |
DateSearch = function() { DateSearch.form = document.getElementById( 'shop_list'); DateSearch.date = new Date(); //올해 DateSearch.date.curYear = DateSearch.date.getYear(); //이번달 DateSearch.date.curMonth = DateSearch.date.getMonth() ; //오늘 DateSearch.date.curDate = DateSearch.date.getDate(); //요일 DateSearch.date.curDay = DateSearch.date.getDay(); //오늘 YYYY-mm-dd DateSearch.getToday = function() { var fullDate = DateSearch.makeFullDate(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate); DateSearch.form.date_s.value = fullDate; DateSearch.f orm.date_e.value = fullDate; } //7일뒤 YYYY-mm-dd DateSearch.getNextSevenDays = function() { document.shop_list.searchtype.value = 'enddate'; var sevenDaysLater = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate + 6) ; var nextSevenYear = sevenDaysLater.getFullYear(); var nextSevenMonth = sevenDaysLater.getMonth(); var nextSevenDate = sevenDaysLater.getDate(); //오늘 DateSearch.form.date_s.value = DateSearch.makeFullDate(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate); //7일뒤 DateSearch.fo rm.date_e.value = DateSearch.makeFullDate(nextSevenYear, nextSevenMonth, nextSevenDate); } //15일뒤 YYYY-mm-dd DateSearch.getNextFiftheenDays = function() { document.shop_list.searchtype.value = 'enddate'; var fifteenDaysLater = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate + 14) ; var nextFifteenYear = fifteenDaysLater.getFullYear(); var nextFifteenMonth = fifteenDaysLater.getMonth(); var nextFifteenDate = fifteenDaysLater.getDate(); //오늘 DateSearch.form.date_s.value = DateSearch.makeFullDate(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate); //15일뒤 DateSearch.form.date_e.value = DateSearch.makeFullDate(nextFifteenYear, nextFifteenMonth, nextFifteenDate); } //이번주 YYYY-mm-dd DateSearch.getThisWeek = function() { var startOfWeek = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate - DateSearch.date.curDay); var startYear = startOfWeek.getFullYear(); var startMonth = startOfWeek.getMonth(); var startDate = startOfWeek.getDate(); var endOfWeek = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.curDate + (6- DateSearch.date.curDay)) ; var endYear = endOfWeek.getFullYear(); var endMonth = endOfWeek.getMonth(); var endDate = endOfWeek.getDate(); //이번주 월 요일 DateSearch.form.date_s.value = DateSearch.makeFullDate(startYear, startMonth, startDate); //이번주 일요일 DateSearch.form.date_e.value = DateSearch.makeFullDate(endYear, endMonth, endDate); } //이번달 YYYY-mm-dd DateSearch.getThisMonth = function() { //달의 첫째 날 DateSearch.date.startOfMonth = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, 1).getDate(); //달의 마지막 날 DateSearch.date.endOfMonth = new Date(DateSearch.date.curYear, DateSearch.date.curMonth, 0).getDate(); DateSearch.form.date_s.value = DateSearch.makeFullDate(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.startOfMonth); DateSearch.form.date_e.value = DateSearch.makeFullDate(DateSearch.date.curYear, DateSearch.date.curMonth, DateSearch.date.endOfMonth); } //전체 DateSearch.resetDate = function() { document.shop_list.searchtype.value = ''; DateSearch.form.date_s.value = ''; DateSearch.form.date_e.value = ''; } // YYYY-mm-dd형식 변환 DateSearch.makeFullDate = function(requestYear, requestMonth, requestDate) { requestMonth = requestMonth+1; if (requestMonth < 10) { requestMonth = '0' + requestMonth; } if (requestDate < 10) { requestDate = '0' + requestDate; } DateSearch.date.fullDate = requestYear + '-' + requestMonth + '-' + requestDate; return DateSearch.date.fullDate; } } DateSearch();
728x90
'JSP&JavaScript&HTML' 카테고리의 다른 글
[Javascript] Function 모음. (0) | 2020.12.02 |
---|---|
[Javascript] Console.log 익스플로어(IE)에서 사용하기 (0) | 2020.12.02 |
[jQuery] serializeObject (0) | 2020.11.20 |
[JSON] serialize(), serializeArray() (0) | 2020.11.20 |
[JSON] 문자열을 JSON 으로.. StringToJson (0) | 2020.11.20 |