希望有人可以提供帮助。
我有以下函数来返回最后 6 个月份的名称(即 6 月、7 月、8 月等),但是,我无法弄清楚如何将每个返回的月份名称用作单独的变量。
我需要这个,以便我可以将每个月的名称输入到一个 sql 查询中,该查询填充了过去 6 个月的表。
非常感谢任何帮助。
function getMonths()
{
var today = new Date();
var month = 1;
var currMonth = month-3;
var monthArray = new Array("January","February","March","April","May","June",
"July","August","September","October","November","December");
var menuMonths = new Array();
var count = 6;
var buffer = 10;
while(count >0)
{
if (currMonth < 0)
currMonth += 12;
if (currMonth >=12 )
currMonth -= 12;
var month = monthArray[currMonth];
menuMonths.push(month);
currMonth = currMonth -1;
count = count -1;
}
return (menuMonths.reverse());
}
console.log (getMonths());