js 日期加减
来源:互联网 发布:模仿优化 编辑:程序博客网 时间:2024/06/08 10:05
Date.prototype.add = Date.prototype.add || function (date,time) { var _time = time.split(' '); var num = parseInt(_time[0]); var type = _time[1]; var result = null; switch (type){ case 'year': result = new Date(date.getFullYear()+num,date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()); break; case 'month': result = new Date(date.getFullYear(),date.getMonth()+num,date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()); break; case 'week': result = new Date(date.getTime()+(1000 * 60 * 60 * 24 * 7 * num)); break; case 'day': result = new Date(date.getTime()+(1000 * 60 * 60 * 24 * num)); break; case 'hours': result = new Date(date.getTime()+(1000 * 60 * 60 * num)); break; case 'minute': result = new Date(date.getTime()+(1000 * 60 * num)); break; case 'second': result = new Date(date.getTime()+(1000 * num)); break; } return { year:result.getFullYear(), month:result.getMonth()+1, day:result.getDate(), hour:result.getHours(), minute:result.getMinutes(), second:result.getSeconds() }; }; //测试数据 var date = new Date(); var year = date.getFullYear(); var month = date.getMonth()+1; var day = date.getDate(); /* 单位 hours minute second day week month year */ console.log(date.add(date,'+1 day')); console.log('now is',year,month,day);
0 0
- JS实现日期加减
- js 日期的加减
- JS日期加减操作
- js 日期加减
- 日期加减天数js
- Js 日期加减
- JS日期加减
- js 日期加减
- JS日期加减
- JS日期加减
- js日期加减
- 【js】日期天数加减
- js日期加减, 日期运算
- JS日期加减--------日期运算
- JS日期加减,日期运算
- JS日期加减,日期运算
- js操作日期加减一天
- js 日期格式化,天数加减
- CANVAS的使用详解
- RSS
- ubuntu安装oracle客户端
- App开发外包流程和防骗技巧
- 关于go语言学习的经历1:2017-1-8
- js 日期加减
- JS深度克隆
- PAT乙级1014
- linux下内存泄露检测工具Valgrind介绍
- 类加载器的父委托机制
- kubernetes(k8s)以及涉及组件简单介绍
- 【spring mvc 教程书籍推荐】
- 强化训练1~3
- 版本号设置--语义化版本控制