JavaScript将月份的日期编号作为数组

时间:2017-03-14 11:40:57

标签: javascript arrays date typescript

大家好,如何才能获得直到今天的数字并将它们写成数组: 结果应该是:

UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 14 of the file C:/Users/Bedri/PycharmProjects/untitled1/main.py. To get rid of this warning, change code that looks like this:

BeautifulSoup([your markup])

to this: BeautifulSoup([your markup], "html.parser") markup_type=markup_type))

4 个答案:

答案 0 :(得分:3)

您可以使用OKinsert into获取日期,然后使用new Date()创建包含所有前几天的数组。



getDate()




另一种选择是使用Array.from()而不是var days = Array.from(Array((new Date).getDate()), (e, i) => i + 1) console.log(days)

的扩展语法



map()




答案 1 :(得分:3)

array=[]  
len=new Date().getDate();
for(i=1;i<=len;i++){
    array.push(i);
}
console.log(array);

答案 2 :(得分:2)

尝试包含此脚本。

First draft : PUT : api/membership/user_id/project_id/group_id

This route associate group with group_id to user if it doesn't exist and remove it if it's associated

答案 3 :(得分:1)

var dateObj = new Date();
var day = dateObj.getUTCDate();
var days =[];
for(var i = 0; i < day; i++ )
{
    days[i] = i+1;
  console.log(days[i]);
}
console.log(days.toString());

https://jsfiddle.net/zt3jhchn/

返回1,2,3,4,5,6,7,8,9,10,11,12,13,14