简体   繁体   English

FullCalendar (React) - 获取当前周/月的日期

[英]FullCalendar (React) - getting dates of current week/month

I am playing out with FullCalendar for React and I can't find in documentation how can I get the start and end date of the current displayed week/month.我正在为 React 使用 FullCalendar,但我在文档中找不到如何获取当前显示的周/月的开始和结束日期。

Does anyone have example on this one?有人有这方面的例子吗?

datesRender will invoke each time the dates displayed are changed每次更改显示的日期时都会调用 datesRender

<FullCalendar

    plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}

    datesRender={(arg) => {
      console.log(arg)
      //arg includes data about current visible dates
      console.log(arg.view.activeStart) //starting visible date
      console.log(arg.view.activeEnd) //ending visible date
    }}

  />

There is no longer datesRender in FullCalendar version v5. FullCalendar 版本 v5 中不再有日期渲染。 Can use datesSet instead which will invoke after the calendar's date range has been initially set or changed.可以使用datesSet代替,它将在日历的日期范围最初设置或更改后调用。

<FullCalendar
    plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}

    datesSet={(dateInfo) => {
        console.log(dateInfo.start) //start of the range the calendar date
        console.log(dateInfo.end) //end of the range the calendar date
    }}
/>

tried @sammyShenker's answer but it didn't work.尝试了@sammyShenker 的答案,但没有奏效。 Rather found a solution.而是找到了解决方案。

<FullCalendar

datesSet={(args) => console.log("###datesSet:", args)}
/>

Output: Output:

{
    "start": "2021-02-27T18:30:00.000Z",
    "end": "2021-04-10T18:30:00.000Z",
    "startStr": "2021-02-28T00:00:00+05:30",
    "endStr": "2021-04-11T00:00:00+05:30",
    "timeZone": "local",
    "view": {
        "type": "dayGridMonth",
        "dateEnv": {
            "timeZone": "local",
            "canComputeOffset": true,
            "calendarSystem": {},
            "locale": {
                "codeArg": "en",
                "codes": [
                    "en"
                ],
                "week": {
                    "dow": 0,
                    "doy": 4
                },
                "simpleNumberFormat": {},
                "options": {
                    "direction": "ltr",
                    "buttonText": {
                        "prev": "prev",
                        "next": "next",
                        "prevYear": "prev year",
                        "nextYear": "next year",
                        "year": "year",
                        "today": "today",
                        "month": "month",
                        "week": "week",
                        "day": "day",
                        "list": "list"
                    },
                    "weekText": "W",
                    "allDayText": "all-day",
                    "moreLinkText": "more",
                    "noEventsText": "No events to display"
                }
            },
            "weekDow": 0,
            "weekDoy": 4,
            "weekText": "W",
            "cmdFormatter": null,
            "defaultSeparator": " - "
        }
    }
}

Then use the start/startStr/end/endStr as per your needs.然后根据您的需要使用 start/startStr/end/endStr。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取当前周/月的日期反应 useEffect - Getting dates of current week/month react useEffect 使用 React DayPicker 获取特定一周的日期数组 - Getting array of dates for a specific week with React DayPicker Airbnb 反应日期范围选择器仅显示当前月份日历未选择日期月份日历 - Airbnb react date range picker only showing current month calendar not selected dates month calender 在以前的日期停止事件下降 fullcalendar react - Stop event dropping in previous dates fullcalendar react React 中的周历 - 选择多个日期的问题 - Week calendar in React - problem with selecting multiple dates 具有全日历反应的周视图中的天之间的距离如何? - How separate between days on the week view with fullcalendar react? 获取 TypeError:`month` 必须是移动 Airbnb/react-dates 中的有效时刻 object - Getting TypeError : `month` must be a valid moment object in mobile Airbnb/react-dates 在本机中显示当前周 - Display current week in react-native React 管理员日期过滤器(今天,本周,上周,本月,上个月) - React Admin Date Filter (Today, This Week, Last Week, This Month, Last Month) 单击下个月或上个月时,将当前日期的新背景色保持为全日历 - keep the new background color of current day in fullcalendar when click on next month or previous month
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM