【问题标题】:Full Calendar messing with my timezone when formatting date格式化日期时,完整日历与我的时区混淆
【发布时间】:2016-03-15 03:49:07
【问题描述】:

我正在实施完整的日历 - 我的 .js 文件看起来像这样 -

$('#calendar').fullCalendar({
        header : {
            left:"prev,next today",
            center:"title",
            right:"agendaWeek,agendaDay"
            },
        timezone: 'Asia/Kolkata',
        defaultView: 'agendaWeek',
        allDaySlot: false,
        editable: true,
        droppable: true,
        selectable: true,
        selectHelper: true,
        eventSources: [{
            type: "POST",
            url: 'cal_func.php',
            async: false,
            data: {action:'get_slots', userid:$userxid, which:$calaction},
            success: function(data){
                if(data.length != 0){
                    return data;
                }else{

                }
            }
        }],
        select: function(start, end){
            if(parseInt($('#mentor').val()) == 1){
                setNotifyMsg('');
            }else{
                if($calaction == 1){
                    var startDate = start.format("YYYY-MM-DD HH:MM:SS");

                    var endDate = end.format("YYYY-MM-DD HH:MM:SS");
                    $title = $('#titleVal').val();
                    var out = addAptToDB($title, startDate, endDate, 0);
                    if(out == 1){
                        //$('#calendar').fullCalendar('renderEvent',{title: $title, start: start, end: end},true);
                        $('#calendar').fullCalendar('refetchEvents');
                    }
                }else{
                    setNotifyMsg('You cannot add an appointment this way.');
                }
            }
            $('#calendar').fullCalendar('unselect');
        }
})

现在,当我选择一个时间段在我的日历中进行预约时,例如从上午 9 点到 10 点。它正在预订上午 9.12 - 10.12 之间的时间段。

我调试了一下,罪魁祸首似乎是'select'中的这一行-

var startDate = start.format("YYYY-MM-DD HH:MM:SS");

在格式化之前,这是输入 -

通过 moment.js 格式化后,这是输出 -

它使用 moment.js 的格式并返回错误的值。我哪里错了?我该如何解决这个问题。

  • 谢谢。

【问题讨论】:

    标签: jquery datetime timezone format fullcalendar


    【解决方案1】:

    这是因为,MM- 指定了月份数。您必须使用正确的格式,例如 'YYYY-MM-DD hh:mm:ss'。

    Formats in moment

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 2016-03-05
      • 2015-06-26
      相关资源
      最近更新 更多