弃用警告:提供的值不在可识别的rfc2822或iso中

w1e3prcc  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(358)

moment.min.js:6弃用警告:提供的值不是可识别的rfc2822或iso格式。moment构造回到js date(),这在所有浏览器和版本中都不可靠。不鼓励使用非rfc2822/iso日期格式,并将在即将发布的主要版本中删除。请参阅http://momentjs.com/guides/#/warnings/js-日期/以获取更多信息。参数:[0]\u IsamentintObject:true、\u isutc:false、\u useutc:false、\u l:undefined、\u i:07/07/2021 12:00 am、\u f:undefined、\u strict:undefined、,\u区域设置:[对象]函数处出错。createfrominputfallback(https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js:6:3248)在gb(https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js:6:19736)在rb(https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js:6:22824)在qb(https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js:6:22691)在pb(https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js:6:22410)对某人(https:///ajax/libs/moment.js/2.18.1/moment.min.js:6:23150)结核病(https:///ajax/libs/moment.js/2.18.1/moment.min.js:6:23184)至少(https:///ajax/libs/moment.js/2.18.1/moment.min.js:6:202)在htmlbuttonelement.eval(webpack:///./scripts/calendar.js?:97:19)在htmlbuttonelement.dispatch(https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:41772)
您好,我的asp.net核心项目有这个问题。我尝试复制此计划程序:https://github.com/esausilva/fullcalendar-aspnet-core 但是
我的js代码如下:

let currentEvent;
const formatDate = date => date === null ? '' : moment(date).format("MM/DD/YYYY h:mm A");
const fpStartTime = flatpickr("#StartTime", {
    enableTime: true,
    dateFormat: "m/d/Y h:i K"
});
const fpEndTime = flatpickr("#EndTime", {
    enableTime: true,
    dateFormat: "m/d/Y h:i K"
});

$('#calendar').fullCalendar({
    defaultView: 'month',
    height: 'parent',
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    eventRender(event, $el) {
        $el.qtip({
            content: {
                title: event.title,
                text: event.description
            },
            hide: {
                event: 'unfocus'
            },
            show: {
                solo: true
            },
            position: {
                my: 'top left',
                at: 'bottom left',
                viewport: $('#calendar-wrapper'),
                adjust: {
                    method: 'shift'
                }
            }
        });
    },
    events: '/Calendar/GetCalendarEvents',
    eventClick: updateEvent,
    selectable: true,
    select: addEvent
});

/**
 * Calendar Methods

**/

function updateEvent(event, element) {
    currentEvent = event;

    if ($(this).data("qtip")) $(this).qtip("hide");

    $('#eventModalLabel').html('Edit Event');
    $('#eventModalSave').html('Update Event');
    $('#EventTitle').val(event.title);
    $('#Description').val(event.description);
    $('#isNewEvent').val(false);

    const start = formatDate(event.start);
    const end = formatDate(event.end);

    fpStartTime.setDate(start);
    fpEndTime.setDate(end);

    $('#StartTime').val(start);
    $('#EndTime').val(end);

    if (event.allDay) {
        $('#AllDay').prop('checked', 'checked');
    } else {
        $('#AllDay')[0].checked = false;
    }

    $('#eventModal').modal('show');
}

function addEvent(start, end) {
    $('#eventForm')[0].reset();

    $('#eventModalLabel').html('Add Event');
    $('#eventModalSave').html('Create Event');
    $('#isNewEvent').val(true);

    start = formatDate(start);
    end = formatDate(end);

    fpStartTime.setDate(start);
    fpEndTime.setDate(end);

    $('#eventModal').modal('show');
}

/**
 * Modal
 * */

$('#eventModalSave').click(() => {
    const title = $('#EventTitle').val();
    const description = $('#Description').val();
    const startTime = moment($('#StartTime').val());
    const endTime = moment($('#EndTime').val());
    const isAllDay = $('#AllDay').is(":checked");
    const isNewEvent = $('#isNewEvent').val() === 'true' ? true : false;

    if (startTime > endTime) {
        alert('Start Time cannot be greater than End Time');

        return;
    } else if ((!startTime.isValid() || !endTime.isValid()) && !isAllDay) {
        alert('Please enter both Start Time and End Time');

        return;
    }

    const event = {
        title,
        description,
        isAllDay,
        startTime: startTime._i,
        endTime: endTime._i
    };

    if (isNewEvent) {
        sendAddEvent(event);
    } else {
        sendUpdateEvent(event);
    }
});

function sendAddEvent(event) {
    axios({
        method: 'post',
        url: '/CalendarController/AddEvent',
        data: {
            "Title": event.title,
            "Description": event.description,
            "Start": event.startTime,
            "End": event.endTime,
            "AllDay": event.isAllDay
        }
    })
    .then(res => {
        const { message, eventId } = res.data;

        if (message === '') {
            const newEvent = {
                start: event.startTime,
                end: event.endTime,
                allDay: event.isAllDay,
                title: event.title,
                description: event.description,
                eventId
            };

            $('#calendar').fullCalendar('renderEvent', newEvent);
            $('#calendar').fullCalendar('unselect');

            $('#eventModal').modal('hide');
        } else {
            alert(`Something went wrong: ${message}`);
        }
    })
    .catch(err => alert(`Something went wrong: ${err}`));
}

function sendUpdateEvent(event) {
    axios({
        method: 'post',
        url: '/Calendar/UpdateEvent',
        data: {
            "EventId": currentEvent.eventId,
            "Title": event.title,
            "Description": event.description,
            "Start": event.startTime,
            "End": event.endTime,
            "AllDay": event.isAllDay
        }
    })
    .then(res => {
        const { message } = res.data;

        if (message === '') {
            currentEvent.title = event.title;
            currentEvent.description = event.description;
            currentEvent.start = event.startTime;
            currentEvent.end = event.endTime;
            currentEvent.allDay = event.isAllDay;

            $('#calendar').fullCalendar('updateEvent', currentEvent);
            $('#eventModal').modal('hide');
        } else {
            alert(`Something went wrong: ${message}`);
        }
    })
    .catch(err => alert(`Something went wrong: ${err}`));
}

$('#deleteEvent').click(() => {
    if (confirm(`Do you really want to delte "${currentEvent.title}" event?`)) {
        axios({
            method: 'post',
            url: '/Calendar/DeleteEvent',
            data: {
                "EventId": currentEvent.eventId
            }
        })
        .then(res => {
            const { message } = res.data;

            if (message === '') {
                $('#calendar').fullCalendar('removeEvents', currentEvent._id);
                $('#eventModal').modal('hide');
            } else {
                alert(`Something went wrong: ${message}`);
            }
        })
        .catch(err => alert(`Something went wrong: ${err}`));
    }
});

$('#AllDay').on('change', function (e) {
    if (e.target.checked) {
        $('#EndTime').val('');
        fpEndTime.clear();
        this.checked = true;
    } else {
        this.checked = false;
    }
});

$('#EndTime').on('change', () => {
    $('#AllDay')[0].checked = false;
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题