JS 联接函数(链式函数)
2015-09-10 08:05
489 查看
Date.prototype.addDay = function (value) {
this.setDate(this.getDate() + value);
return this;
}
Date.prototype.addMonth = function (value) {
this.setMonth(this.getMonth() + value);
return this;
}
Date.prototype.addYear = function (value) {
this.setFullYear(this.getFullYear() + value);
return this;
}
Date.prototype.formatToYMD=function(date) {
return this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate();
}
var ndt = new Date("2015-12-31");
ndt = ndt.addDay(1);
ndt = ndt.addMonth(1);
ndt = ndt.addYear(1);
var ndt2 = new Date("2015-12-31");
ndt2 = ndt2.addYear(1).addDay(1).addMonth(1).formatToYMD();
console.log("明年下个月的明天 " + ndt);
console.log("明年下个月的明天 " + ndt2);
this.setDate(this.getDate() + value);
return this;
}
Date.prototype.addMonth = function (value) {
this.setMonth(this.getMonth() + value);
return this;
}
Date.prototype.addYear = function (value) {
this.setFullYear(this.getFullYear() + value);
return this;
}
Date.prototype.formatToYMD=function(date) {
return this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate();
}
var ndt = new Date("2015-12-31");
ndt = ndt.addDay(1);
ndt = ndt.addMonth(1);
ndt = ndt.addYear(1);
var ndt2 = new Date("2015-12-31");
ndt2 = ndt2.addYear(1).addDay(1).addMonth(1).formatToYMD();
console.log("明年下个月的明天 " + ndt);
console.log("明年下个月的明天 " + ndt2);
相关文章推荐
- javascript验证
- Javascript邮件管理
- 201509010 javascript事件-多物体运动
- 检测 HTML5\CSS3\JAVASCRIPT 在浏览器的适应情况
- JavaScript中实现Map的示例代码
- 谈谈impress.js初步理解
- JS实现自动变化的导航菜单效果代码
- JS实现自动变换的菜单效果代码
- js基于面向对象实现网页TAB选项卡菜单效果代码
- 45个实用的JavaScript技巧、窍门和最佳实践
- JSP九大隐式对象
- js基本数据类型
- Canvas 在高清屏下绘制图片变模糊的解决方法
- JS日期比较大小 给定时间和持续时间计算最终时间
- JS 日期 与 字符串 的 相互 转换
- js浮点数精度问题
- js中setInterval与setTimeout用法
- Js 冒泡事件阻止
- 常用JSTL标签的使用
- Ember.js 入门指南——枚举(enumerables)