<script type=
"text/javascript"
>
function
myDate2(date){
this
.date =
new
Date(date);
this
.Y =
function
(){
return
this
.date.getFullYear();
}
this
.m =
function
(){
var
m = (
this
.date.getMonth()+1).toString();
if
(m.length==1)
return
"0"
+m;
return
m;
}
this
.d =
function
(){
var
d =
this
.date.getDate().toString();
if
(d.length==1)
return
"0"
+d;
return
d;
}
}
myDate2.prototype.Format =
function
(format){
if
(format==
"yyyy"
){
return
this
.Y();
}
else
if
(format==
"yyyy-mm"
){
return
this
.Y()+
"-"
+
this
.m();
}
else
if
(format==
"yyyy-mm-dd"
){
return
this
.Y()+
"-"
+
this
.m()+
"-"
+
this
.d();
}
throw
new
error(
"非法的格式"
);
}
myDate2.prototype.AddDate =
function
(Y,m,d){
this
.date.setFullYear(parseInt(
this
.Y())+Y);
this
.date.setMonth(parseInt(
this
.m())+m-1);
this
.date.setDate(parseInt(
this
.d())+d);
return
this
;
}
function
myDate(date){
return
new
myDate2(date);
}
var
d = myDate(
"2016-02-14"
);
d.AddDate(0,0,10);
console.log(d.Format(
"yyyy-mm-dd"
));
</script>