js在当前日期基础上,加1天 3天 7天 15天
2024-08-24 00:58:13
需求 点击保障期的天数 根据起始时间算出结束时间
代码
//点击保障期触发的方法
periodChange(val,id){
this.activeNumperiod=val
this.submitData.endDate=this.getNextDay(this.submitData.startDate,id)+' 00:00:00' //调用格式化日期的方法,将开始时间和要加的天数传进去
},
getNextDay(d,t){
console.log(d,t)//格式为---2019-02-13 3
d = new Date(d);
console.log(d)//格式为---Wed Feb 13 2019 08:00:00 GMT+0800 (中国标准时间)
d = +d + (1000*60*60*24)*t;
console.log(d)//格式为--时间戳1550275200000
d = new Date(d);
console.log(d)//格式为---Sat Feb 16 2019 08:00:00 GMT+0800 (中国标准时间)
return new Date(d).format("yyyy-MM-dd") //格式为"2019-02-16 00:00:00"
},
补充
// 为Date原型添加时间格式化方法
Date.prototype.format = function (fmt) {
let 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 (let 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
}
最新文章
- penpyxl basic function demo code
- C Primer Plus_第8章_字符输入输出和输入确认_编程练习
- h5网站和好看的动画网址
- C#常用代码集合(1)
- WebApi系列~在WebApi中实现Cors访问
- ajax头像上传
- leetcode:Isomorphic Strings
- jquery-easyui使用
- linux VM命令下查找
- firefox关于about:config的常用配置
- iOS开发之视图控制器(UIViewController)
- [Unity3D]Unity3D圣骑士当游戏开发商遭遇Mecanim动画系统
- ubuntu升级php版本
- 设计模式--MVC(C++版)
- ASP.NET Core 2.1与2.2 SignalR CORS 跨域问题
- PHP左侧菜单栏的管理与实现
- 小程序实践(五):for循环绑定item的点击事件
- English trip V2 - A 1. Mother tongue 母语 Teacher:Lamb Key: Comparative 比较级 superlative 最高级
- postgresql-查看表大小
- join() 方法详解及应用场景