js AddDays ,AddYears
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | //日期类型变量格式化,默认格式"xxxx-xx-xx" Date.prototype.Format = function (fmt) { fmt = fmt || "yyyy-MM-dd" ; var o = { "M+" : this .getMonth() + 1, //月份 "d+" : this .getDate(), //日 "h+" : this .getHours(), //小时 "m+" : this .getMinutes(), //分 "s+" : this .getSeconds(), //秒 "q+" : Math.floor(( this .getMonth() + 3) / 3), //季度 "S" : this .getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, ( this .getFullYear() + "" ).substr(4 - RegExp.$1.length)); for ( var k in o) if ( new RegExp( "(" + k + ")" ).test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (( "00" + o[k]).substr(( "" + o[k]).length))); return fmt; } //添加天 Date.prototype.AddDays = function (d) { this .setDate( this .getDate() + d); return this ; } //添加周 Date.prototype.AddWeeks = function (w) { this .addDays(w * 7); return this ; } //添加月 Date.prototype.AddMonths = function (m) { var d = this .getDate(); this .setMonth( this .getMonth() + m); if ( this .getDate() < d) this .setDate(0); return this ; } //添加年 Date.prototype.AddYears = function (y) { var m = this .getMonth(); this .setFullYear( this .getFullYear() + y); if (m < this .getMonth()) { this .setDate(0); } return this ; } //日期加减函数,strDate传入你需要的日期,格式"xxxx-xx-xx"。days传要加减的日期数,往前传正数,往后传负数 function AddDate(strDate, days, fmt) { var date = new Date(strDate); date.setDate(date.getDate() + days); return date.Format(fmt); } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
2019-04-23 在.txt文件的首行写上.LOG后,后面每次对改文本文件进行编辑后,系统会自动在编辑内容后记录操作时间
2018-04-23 HTTPS简单原理介绍