Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript管理日历中包含30天的月份和2月_Javascript_Reactjs_Calendar_Leap Year - Fatal编程技术网

如何使用javascript管理日历中包含30天的月份和2月

如何使用javascript管理日历中包含30天的月份和2月,javascript,reactjs,calendar,leap-year,Javascript,Reactjs,Calendar,Leap Year,这是在组件加载时调用的函数。函数返回所有月份,有31天。2月和30天的月份也返回31天。如何将月数限制为30天,闰年将2月限制为28或29天 const getCalendarCells=(日期、项目)=>{ var单元格=[]; 试一试{ if(items==未定义| | items==空){ 项目={}; } /*-----本月初-----*/ var start=新日期(); start.setMonth(date.getMonth()); start.setFullYear(date.

这是在组件加载时调用的函数。函数返回所有月份,有31天。2月和30天的月份也返回31天。如何将月数限制为30天,闰年将2月限制为28或29天

const getCalendarCells=(日期、项目)=>{
var单元格=[];
试一试{
if(items==未定义| | items==空){
项目={};
}
/*-----本月初-----*/
var start=新日期();
start.setMonth(date.getMonth());
start.setFullYear(date.getFullYear());
开始。设置日期(1);
/*-----查找日历日期的开始日期-----*/
while(start.getDay()!=0){
start.setDate(start.getDate()-1);
}
/*-----查找星期的所有日历日标题-----*/
推送(['SUN','MON','TUE','WED','THU','FRI','SAT']);
/*-----查找所有日历单元格-----*/
var-weekCells=[];
对于(变量i=0;i 0&&i%7==0){
推(周细胞);
weekCells=[];
}
如果(i==42){
打破
}否则{
变量类型=(start.getMonth()==date.getMonth()&&start.getFullYear()==date.getFullYear())?“THIS':“OTHER”;
weekCells.push({
数据:(type=='THIS'?项[start.getDate().toString()]:{}),
值:新日期(start.toString()).getDate(),
类型:类型
});
start.setDate(start.getDate()+1);
}
}
console.log(单元格)
setReport(单元格);
}捕获(ex){}

}
我给你写了一个片段。请在a中添加相关的HTML和CSS。这是否回答了您的问题?使用像moment.js、Luxon或DayJS这样的外部库是一种选择吗?@ClydeFrog巨大的浪费。只需执行
var end=newdate(start.getFullYear(),start.getMonth()+1,0)
我应该在哪里添加此行。这只返回一个月的结束日期。如果我需要所有的飞蛾一起约会呢?