大佬救救小弟,有一个很简单的需求。做一个picker,里面的时间是7天之内。需要用js计算?

小程序 文章 2020-08-05 17:02 676 0 全屏看文

AI助手支持GPT4.0

大佬救救小弟,有一个很简单的需求。做一个picker,里面的时间是7天之内。需要用js计算?The boss has a very simple need to save the little brother. To be a picker, the time inside is within 7 days. Need to use js calculation?

大佬救救小弟,有一个很简单的需求。做一个picker,里面的时间是7天之内。需要用js计算?

大佬们,小弟的js太弱了。

比如今天是8月5日,我要算7天之内的日子。=》那就是8月6日,8月7日,。。。8月12日,这样七天。(要把这7天循环出来)随着日子的变化,数据自动变化。这是要用时间戳来计算吧?希望大佬说仔细点。手摸手教学。

效果如下:



Guys, my JS is too weak. For example, today is August 5th. I want to count the days within 7 days. =That's August 6, August 7,... August 12, seven days. (to cycle these 7 days) as the days change, the data changes automatically. This is to use the time stamp to calculate, right? I hope you can be more careful. Hand to hand teaching. The results are as follows:

回答:

They Say:

这个的缺点是格式被固定,其他全是优点

不然就js计算,处理时间用moment.js比较方便

微喵网络:
let now=new Date(),	year=now.getFullYear(),	month=now.getMonth(),	day=now.getDate(),	days=[]for(var i=0;i<7;i++){	days.push((new Date(year, month, (day+i)).getMonth()+1)+'月'+new Date(year, month, (day+i)).getDate()+'日')}console.log(days)
?:

picker有start 和 end start写今天的日期 end写七天后的日期。

function getNowFormatDate() {    var date = new Date();    var seperator1 = "-";    var seperator2 = ":";    var month = date.getMonth() + 1;    var strDate = date.getDate();    if (month >= 1 && month <= 9) {        month = "0" + month;    }    if (strDate >= 0 && strDate <= 9) {        strDate = "0" + strDate;    }    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate            + " " + date.getHours() + seperator2 + date.getMinutes()            + seperator2 + date.getSeconds();    return currentdate;}var date = new Date();//这里的7就是你要加的天数,减也可以。年、月会相应加上去,值得注意的是date.getMonth()得到的月份比实际月份小1,所以实际月份是(date.getMonth()+1)date.setDate(date.getDate() + 7);console.log(date.getFullYear() +"-"+ (date.getMonth()+1) +"-"+ date.getDate());


-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
微信内部浏览器IP访问时,多了个%20a,昨天还好好的
如何实现 跳转到目标页面的最底部位置?
新创建第三方应用name不再返回
没有工单,只能公开发帖吗?
有哪位大佬知道为什么我已经从后台获取到了数据,但是为什么无法显示到页面上吗?
随便看看
教育科技公司申请微信支付被拒绝? 4799
微信公众号免300认证教程 5892
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 5299
小程序广告组件通过审核,但是小程序内没有显示广告? 5067
企业微信通讯录账号被管理员误/恶意删除,怎么办? 9568
问题? 9048
如何快速搭建抽奖助手小程序(无需代码知识) 6177
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 7472
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 6793
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 6128