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

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