JS 날짜 덧셈과 뺄셈 기능 정리

巴扎黑
풀어 주다: 2016-12-06 11:07:00
원래의
1471명이 탐색했습니다.

// 날짜 추가
function AddDays(date,value)
{
date.setDate(date.getDate()+value)
}
// 월 추가
function AddMonths(날짜,값)
{
date.setMonth(date.getMonth()+value);
}
// 연도 추가
function AddYears(날짜,값)
{
date.setFullYear(date.getFullYear()+value);
}
// 오늘인지 여부
function IsToday(date)
{
return IsDateEquals( date ,new Date());
}
// 이번 달인지 여부
function IsThisMonth(date)
{
return IsMonthEquals(date,new Date()); 🎜>}
// 두 날짜의 연도가 같은지 여부
function IsMonthEquals(date1,date2)
{
return date1.getMonth()==date2.getMonth()&&date1.getFullYear( )==date2.getFullYear()
}
// 날짜가 같은지 확인
function IsDateEquals(date1,date2)
{
return date1.getDate()==date2 .getDate()&&IsMonthEquals(date1 ,date2);
}
// 특정 날짜에 해당하는 월의 일수를 반환합니다.
function GetMonthDayCount(date)
{
switch( date.getMonth()+1)
{
케이스 1:케이스 3:케이스 5:케이스 7:케이스 8:케이스 10:케이스 12:
return 31
케이스 4:케이스 6; :case 9:case 11:
return 30;
}
//feb:
date=new Date(date)
var lastd=28
date.setDate( 29);
while(date.getMonth ()==1)
{
lastd++
AddDays(date,1);
}
return lastd;
// 두 자리 연도 반환
function GetHarfYear(date)
{
var v=date.getYear()
if(v>9)return v.toString(); ;
return "0"+v;
}
// 월 반환(두 자리로 수정됨)
function GetFullMonth(date)
{
var v=date.getMonth ()+1;
if(v> ;9)return v.toString();
return "0"+v;}
// 반환 날짜(두 자리로 수정됨)
function GetFullDate(date)
{
var v=date.getDate()
if(v>9)return v.toString()
return "0"+v; >}
// 문자열 바꾸기
function 바꾸기(str,from,to)
{
return str.split(from).join(to)
}
// 형식화된 날짜 표현
function FormatDate(date,str)
{
str=Replace(str,"yyyy",date.getFullYear())
str=Replace(str,"MM" ,GetFullMonth(날짜));
str=Replace(str,"dd",GetFullDate(날짜))
str=Replace(str,"yy",GetHarfYear(date))
str= 바꾸기(str,"M", date.getMonth()+1);
str=Replace(str,"d",date.getDate())
return str; // 통합 날짜 형식
function ConvertDate(str)
{
str=(str+"").replace(/^s*/g,"").replace(/s*$/g, ""); // 공백
var d
if(/^[0-9]{8}$/.test(str)) // 20040226 -> 26
{
d =new Date(new Number(str.substr(0,4)),new Number(str.substr(4,2))-1,new Number(str.substr(6, 2)));
if (d.getTime())return d;
d=new Date(str)
if(d.getTime())return d; >d=new Date(Replace(str ,"-","/"));
if(d.getTime())return d;
return null; 함수

인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!