Javascript 如何在 fullcalendar 上获取开始和结束时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3967910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can get start and end time on fullcalendar?
提问by Pooky
how can i get startand endtime of visible days in fullcalendar?
如何在 fullcalendar 中获取可见天数的开始和结束时间?
I need it for use in another javascript instace. Is there some function like -
我需要它在另一个 javascript 实例中使用。有没有类似的功能 -
$('calender').getStartTime();
?
?
回答by Matthieu
If you're looking for the visiblestart and end date, that would be the visStart
and visEnd
property of the view object in version 1:
如果您正在寻找可见的开始和结束日期,那将是版本 1 中视图对象的visStart
andvisEnd
属性:
$('calender').fullCalendar('getView').visStart
$('calender').fullCalendar('getView').visEnd
and that would be intervalStart
and intervalEnd
in version 2:
这将是intervalStart
和intervalEnd
在版本 2 中:
$('calender').fullCalendar('getView').intervalStart
$('calender').fullCalendar('getView').intervalEnd
If you're looking for the start and end date of the current week / month, that would be the start
and end
property of the current view object:
如果您正在查找当前周/月的开始日期和结束日期,这将是当前视图对象的start
andend
属性:
$('calendar').fullCalendar('getView').start
$('calendar').fullCalendar('getView').end
Reference : Full Calendar documentation.
参考:完整的日历文档。
回答by Scott
I don't know why I'm seeing such different behavior but thanks to the others, I got in the right direction but the "start" and "end" are moment() objects. Thus to get the actual date, you need to use:
我不知道为什么我会看到如此不同的行为,但多亏了其他人,我找到了正确的方向,但“开始”和“结束”是 moment() 对象。因此,要获得实际日期,您需要使用:
$('calendar').fullCalendar("getView").start.format()
$('calendar').fullCalendar("getView").end.format()
Works exactly like I need and what the OP asked. NOTE: The end date is one day after the calendar. That is, the calendar I'm looking at starts on Sunday 7/31/16 ends on Saturday 9/10/16 - and the date given me are 2016-07-31 and 2016-09-11 (one day after the date shown technically - of course if you say "00:00:00" of those days you'll be accurate).
完全按照我的需要和 OP 的要求工作。注意:结束日期是日历后一天。也就是说,我正在查看的日历从 16 年 7 月 31 日星期日开始,到 16 年 9 月 10 日星期六结束 - 给我的日期是 2016-07-31 和 2016-09-11(日期后一天技术上显示 - 当然,如果你说那些日子的“00:00:00”,你会是准确的)。
回答by auswalk
$('calendar').fullCalendar('getView').start
$('calendar').fullCalendar('getView').end
回答by Raja Rama Mohan Thavalam
You need to give id/class what you specified jquery full calendar
你需要给 id/class 你指定的 jquery full calendar
var start_date = $('#schedule-events').fullCalendar('getView').start
var end_date = $('#schedule-events').fullCalendar('getView').end
Above #schedule-events of the full calendar .. you should give the id of the full calendar
以上#schedule-events of the full calendar ..你应该给出完整日历的id
Example :
例子 :
$('#schedule-events').fullCalendar({
eventRender: function(event, element) {
var start_date = $('#schedule-events').fullCalendar('getView').start
var end_date = $('#schedule-events').fullCalendar('getView').end
console.log(start_date +'sart----------end date'+end_date)
}
......................etc..........
......................等等..........
回答by Sachin G.
Just posting it for others who might be looking for angular solution.
只是将其发布给可能正在寻找角度解决方案的其他人。
For start date this.calendar.getApi().view.activeStart
and for end date
this.calendar.getApi().view.activeEnd
对于开始日期this.calendar.getApi().view.activeStart
和结束日期
this.calendar.getApi().view.activeEnd
You can follow https://fullcalendar.io/docs/angularto get fullcalendar api - getApi() to use above methods.
您可以按照https://fullcalendar.io/docs/angular获取 fullcalendar api - getApi() 以使用上述方法。
回答by Michael Stachura
version 4
版本 4
You can just use calendar object and get satrt/end dates
您可以只使用日历对象并获取 satrt/end 日期
var start = calendar.view.view.activeStart;
var end = calendar.view.view.activeEnd;