Javascript 全日历结束日期错了一天

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27407052/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:07:05  来源:igfitidea点击:

Fullcalendar end date wrong by one day

javascriptfullcalendar

提问by Cássio Godinho

I am making a fullCalendar backed car reservation functionality. This is the coffescript file.

我正在制作一个 fullCalendar 支持的汽车预订功能。这是 coffescript 文件。

    updateEvent = (event, delta, revertFunc) ->
      $.ajax
        type: "PUT"
        dataType: "json"
        success: (data) ->
            alert "Success"
        error: (data) ->
            revertFunc()
            errors = data.responseJSON.reservations[0][1]
            for message of errors
                alert errors[message]
        url: event.updateUrl
        data:
          reservation:
            reservation_start: event.start.format('DD-MM-YYYY')
            reservation_end: event.end.format('DD-MM-YYYY')
            transport_id: event.transport_id
            user_id: event.user_id

$(document).ready ->
  $(".calendar").fullCalendar
    events: gon.path
    eventDrop: updateEvent
    eventResize: updateEvent

And this is JSON feed with the events.

这是带有事件的 JSON 提要。

[{"start":"2014-12-17T00:00:00.000Z","end":"2014-12-21T00:00:00.000Z","title":"Cassio Godinho","url":"/reservas/44/edit","allDay":true,"editable":true,"updateUrl":"/reservation/44","transport_id":1,"user_id":1}]

The enddate is 2014-12-21but this is what I have on the calendar enter image description here

end日期2014-12-21,但这是我的日历在此处输入图片说明

The documentation says something about this (I think):

文档对此有一些说明(我认为):

endParam
It is the moment immediately after the event has ended. For example, if the last full day of an event is Thursday, the exclusive end of the event will be 00:00:00 on Friday!

But im not quite sure what to do with this information...

但我不太确定如何处理这些信息......

采纳答案by Shaded

I think the key word in the directions is exclusiveso whatever time you specify will not be included in the date range.

我认为方向中的关键词是exclusive无论您指定的时间都不会包含在日期范围内。

So in your case "2014-12-21T00:00:00.000Z"would mean that the event would no longer exists at the very beginning of 12-21. If you want the event to go through 12-21 you'd want to set the end time to "2014-12-22T00:00:00.000"(first possible time in 12-22).

因此,在您的情况下,"2014-12-21T00:00:00.000Z"这意味着该事件在 12-21 开始时将不再存在。如果您希望事件通过 12-21,您需要将结束时间设置为"2014-12-22T00:00:00.000"(12-22 中的第一个可能的时间)。

回答by user3440787

I had the same issue and i finally figured out.

我有同样的问题,我终于想通了。

I was using full day TRUE, as per the documentation if you use full day true it will behave in time.

我使用的是 full day TRUE,根据文档,如果您使用 full day true,它将及时运行。

so first, I changed full day to FALSE, then

所以首先,我把一整天都改成了 FALSE,然后

in my end day I added $endDate."T23:59:00";

在我结束的那一天,我添加了$endDate."T23:59:00";

This worked for me.

这对我有用。

回答by Sam Pritchard

You need to set nextDayThreshold: '00:00' and it will show the last day!

您需要设置 nextDayThreshold: '00:00' 它将显示最后一天!

回答by Rudresh Ajgaonkar

The best part is append 20:00:00 to the end date as follow:

最好的部分是将 20:00:00 附加到结束日期,如下所示:

var ed = $("endDate").val();
newVar = ed+" 20:00:00";

Thats all you need.

这就是你所需要的。

回答by Elvis Hajdar

I had the same problem, but i experimented with the time and that was the resolution :)

我遇到了同样的问题,但我尝试了时间,这就是解决方案:)

2014-12-21T00:00:00 => 2014-12-21T23:59:00 this will solve your problem.

2014-12-21T00:00:00 => 2014-12-21T23:59:00 这将解决您的问题。

回答by Ryan McArthur

If you are setting your end date for 0 hours, min, sec, etc of 12-21-2014 there is no time in that day for an event to show.

如果您将结束日期设置为 12-21-2014 的 0 小时、分钟、秒等,则当天没有时间显示事件。

You may need to advance your end date to 0 hours of the next day since you have the event setup as an all day event, however uou may also be fine just advancing the time any amount (such as an hour) so that the event falls inside of the desired end date, then being an all day event it should render.

您可能需要将结束日期提前到第二天的 0 小时,因为您将事件设置为全天事件,但是您也可以将时间提前任何数量(例如一小时)以便事件下降在所需的结束日期内,然后作为它应该呈现的全天事件。

It would be nice if their event object included a duration parameter you could set, at least I didn't see one in their documentation.

如果他们的事件对象包含您可以设置的持续时间参数会很好,至少我没有在他们的文档中看到一个。

回答by Anand

In AngularChange end date time with current time, when end date time greator than 23:59:59`

在角变化的结束日期时间与当前时间,当结束日期时间greator比23:59:59`

this.calendarOptions = {
  editable: false,
  eventLimit: false,
  validRange: {
    start: '',
    end: new Date(new Date().getUTCFullYear(), new Date().getUTCMonth())
  },
  header: {
    left: '',
    center: 'title',
    right: 'prev,next'
  },
  eventSources: [

    // your event source
    {
      events: (start, end, timezone, callback) => {

        var data = [];


        data.push(new Date("2019-04-11T00:19:02"))
        data.push(new Date("2019-04-12T00:19:02"))
        data.push(new Date("2019-04-13T00:19:02"))

        var eventData = [];

        var calendarEvents: CalendarEvents = new CalendarEvents();
        calendarEvents.start = data[0];

        //Change end time, because of when end date time is greator than 23:59:59 then end date not marked
        var m = moment(data[data.length - 1], 'ddd MMM D YYYY HH:mm:ss ZZ');
        m.set({ h: new Date().getHours() });
        calendarEvents.end = m.toDate();

        calendarEvents.allDay = false;
        eventData.push(calendarEvents);

        callback(eventData);
      },
      color: '#f99500',   // an option!
      textColor: 'black', // an option!
      // displayEventTime: false,
    }
    // any other sources...

  ],
  timeFormat: 'HH:mm'
};

`

`

回答by Hamza

I dont know if its still usefull, but you can use this method, add a day to your end date using :

我不知道它是否仍然有用,但是您可以使用此方法,使用以下方法在结束日期中添加一天:

$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P0Y0M1DT0H0M0S'));

this will increment your end date by one day.

这会将您的结束日期增加一天。

回答by Shafiq

I was also facing the same and resolved it by adding "T23:59:00"to the end date i.e "end"=> $end_date."T23:59:00",

我也面临同样的问题,并通过添加"T23:59:00"到结束日期 ie "end"=>来 解决它$end_date."T23:59:00"

回答by Cássio Godinho

"Fixed" the issue by setting start and end times to the events.

通过设置事件的开始和结束时间来“修复”该问题。