From 7d2cd85f4b01985f3c45d213e35ba7a75443cad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E9=95=BF=E5=BE=81?= Date: Tue, 11 Apr 2023 10:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E6=9C=9F=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=87=E4=BB=B6FDate.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FDate.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 FDate.js diff --git a/FDate.js b/FDate.js new file mode 100644 index 0000000..c6975d5 --- /dev/null +++ b/FDate.js @@ -0,0 +1,30 @@ +//时间格式化 +Date.prototype.format = function (fmt) { + fmt = fmt ?? "yyyy-MM-dd HH:mm:ss"; + date = new Date(this); + var o = { + "M+": date.getMonth() + 1, //月份 + "d+": date.getDate(), //日 + "H+": date.getHours(), //小时 + "m+": date.getMinutes(), //分 + "s+": date.getSeconds(), //秒 + "q+": Math.floor((date.getMonth() + 3) / 3), //季度 + "S": date.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(fmt)) + fmt = fmt.replace(RegExp.$1, (date.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; +} +//为当前日期增加i天 +Date.prototype.addDays = function (i) { + let td = new Date(this); + return new Date(td.setDate(td.getDate() + i)) +} +//为当前日期增加i月 +Date.prototype.addMonths = function (i) { + let td = new Date(this); + return new Date(td.setMonth(td.getMonth() + i)) +}