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

小程序 文章 2020-08-05 17:02 583 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群

相关文章
如何循环一个数字变量?
微信开放平台邮箱被占用,无法找回密码怎么办?
疑似QQ浏览器带头违反《微信小程序平台运营规范》,请运营专员出来解释一下?
微信小程序点击右上角转发时(onShareAppMessa),怎么判断用户是转发成功了?还是取消了?
公众号名称为三个英文单词,中间有空格,视频号名称不能有空格,两者名称无法一致,无法认证?
随便看看
无法打开业务域名,web_view填写的是https 显示的确实http? 313
通过open-type="chooseAvatar"获取头像的地址多久有效? 1897
如何用旧的appId和旧的openId还有新的appId生成新的openId? 459
H5唤起小程序,只能在手机端吗?不支持在PC端吗? 697
微信端小程序突然无法正常使用? 464
代理IP可用性测试工具 1821
我在diy可视化工具上做了一个小程序,请问怎么发布? 387
为什么page-container弹出的框不是半页式? 746
open-data组件获取不到头像 昵称? 1056
只有小程序体验版才能进入的特定页面,能否开发成后台管理平台来使用? 517