일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- MySQL
- header setting
- docker
- React
- generate pojos
- NextJS
- jpa entity자동
- SpringBoot
- Java
- dto valid
- Next.js 14
- spring boot
- java9
- JavaScript
- java8
- 리눅스
- swagger
- docker 설치
- jvm
- spring
- ollama langflow
- memcached
- JPA
- 도커
- generate entity
- CentOS6
- 초기 구축
- custom valid
- 헤더 설정
- 초기 세팅
- Today
- Total
개발자의 길
[자바스크립트] 날짜 계산 본문
function getLastDay(mm,yy){
var nDays;
var nMonthDay = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if (isLeapYear(yy)){
nMonthDay[1]=29;
}
nDays=nMonthDay[mm];
return nDays;
}
function statDate(sType){
if(sType=="")return;
var sType = sType;
var fSearch = window.document.frmForm;
var today = new Date();
var curYear = today.getFullYear();
var curMonth = today.getMonth()+1;
var curMonthDay = 0;
var curDate = today.getDate();
var curDay = today.getDay();
var curTime=today.getTime();
var startYear = 0;
var startMonth = 0;
var startDate = 0;
var endYear = 0;
var endMonth = 0;
var endDate = 0;
curMonthDay = getLastDay(curMonth-1,curYear);
//이번달
if (sType == 'this_month'){
startYear = curYear;
startMonth = curMonth;
startDate = "1";
endYear = curYear;
endMonth = curMonth;
endDate = getLastDay(startMonth-1,startYear);
}else if (sType == 'this_week'){//이번주
startYear = curYear;
startMonth = curMonth;
startDate = curDate-curDay;
if(startDate<=0){
if ((curMonth - 1) <= 0)
{
startYear = startYear - 1;
startMonth = 12;
startDate = getLastDay(11,curYear) + (curDate-curDay);
}else
{
startDate = getLastDay(curMonth-2,curYear) + (curDate-curDay);
startMonth = curMonth-1;
}
}
endYear = curYear;
endMonth = curMonth;
endDate = curDate;
}else if (sType == 'today'){//오늘
startYear = curYear;
startMonth = curMonth;
startDate = curDate;
endYear = curYear;
endMonth = curMonth;
endDate = curDate;
}else if (sType == 'yesterday'){//어제
startYear = curYear;
startMonth = curMonth;
if ((curDate-1) < 1)
{
startDate = getLastDay(curMonth-2,curYear);
if ((curMonth-1) < 1)
{
startMonth = 12;
startYear = curYear - 1;
if(curDate==1)
startDate = getLastDay(startMonth-1,curYear);
}else {
startMonth = curMonth - 1;
if(curDate==1)
startDate = getLastDay(startMonth-1,curYear);
}
}else {
startDate = (curDate-1);
}
endYear = startYear;
endMonth = startMonth;
endDate = startDate;
}else if (sType == 'prev_7'){//지난주
startYear = curYear;
startMonth = curMonth;
startDate = (curDate-curDay)-7;
if(startDate<=0){
if ((curMonth - 1) <= 0)
{
startYear = startYear - 1;
startMonth = 12;
startDate = getLastDay(11,curYear) + (curDate-curDay)-7;
}else
{
startDate = getLastDay(curMonth-2,curYear) + (curDate-curDay)-7;
startMonth = curMonth-1;
}
}
endYear = curYear;
endMonth = curMonth;
endDate = curDate-curDay-1;
if(endDate<=0){
if ((endMonth - 1) <= 0)
{
endYear = endYear - 1;
endMonth = 12;
endDate = getLastDay(11,endYear) + (curDate-curDay)-1;
}else
{
endDate = getLastDay(endMonth-2,endYear) + (curDate-curDay)-1;
endMonth = endMonth-1;
}
}
}else if (sType == 'prev_week'){//지난7일
startYear = curYear;
startMonth = curMonth;
startDate = curDate-7;
endYear = curYear;
endMonth = curMonth;
endDate = curDate;
if ((curDate)-7 <= 0)
{
if ((curMonth - 1) <= 0)
{
startYear = startYear - 1;
startMonth = 12;
startDate = getLastDay(11,curYear) + (curDate-7);
}else
{
startDate = getLastDay(curMonth-2,curYear) + (curDate-7);
startMonth = curMonth-1;
}
}
}else if (sType == 'prev_month'){//지난달
startYear = curYear;
startMonth = curMonth-1;
startDate = 1;
if ((curMonth-1) < 1)
{
startYear = curYear - 1;
startMonth = 12;
}
if (startDate >getLastDay(startMonth-1,startYear))
startDate = getLastDay(startMonth-1,startYear);
endYear = curYear;
endMonth = curMonth-1;
endDate = getLastDay(startMonth-1,startYear);
}else if (sType == 'prev_3month'){
startYear = curYear;
startMonth = curMonth-3;
startDate = curDate;
if ((curMonth-3) < 1)
{
startYear = curYear - 1;
startMonth = 12+curMonth-3;
}
if (startDate >getLastDay(startMonth-1,startYear))
startDate = getLastDay(startMonth-1,startYear);
endYear = curYear;
endMonth = curMonth;
endDate = curDate;
}else if (sType == 'prev_6month'){
startYear = curYear;
startMonth = curMonth-6;
startDate = curDate;
if ((curMonth-3) < 1)
{
startYear = curYear - 1;
startMonth = 12+curMonth-3;
}
if (startDate >getLastDay(startMonth-1,startYear))
startDate = getLastDay(startMonth-1,startYear);
endYear = curYear;
endMonth = curMonth;
endDate = curDate;
}
if (startMonth < 10)
startMonth = "0" + startMonth;
if (startDate<10)
startDate = "0" + startDate;
if (endMonth < 10)
endMonth = "0" + endMonth;
if (endDate<10)
endDate = "0" + endDate;
document.getElementById("srtdate").value=startYear + "." + startMonth + "." + startDate;
document.getElementById("enddate").value=endYear + "." + endMonth + "." + endDate;
}
'2. JS' 카테고리의 다른 글
jQuery를 활용한 홈페이지 개발의 기본인 입력폼 제작 (0) | 2010.01.10 |
---|---|
비밀번호 체크 자바스크립트 [영문+숫자 혼합] (2) | 2010.01.05 |
delay 시키는 함수 setTimeout,setInterval (1) | 2009.12.17 |
자바스크립트 정규식(2) (0) | 2009.11.25 |
자바 스크립트 정규식 (0) | 2009.11.25 |
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.