FullCalendar时区不会修改客户端的时间

I am experiencing a frustrating issue which I've been working on all night. Long story short, if someone in New York creates an event at 2Pm, I'd like that event to show as 8Pm for someone viewing the calendar in Europe (they are six hours ahead let's say).

My fullcalendar configs look like this:

  function renderSchedule(timezone) {
     var userSchedule = $('#user-schedule').fullCalendar({
             header: {
                 left: 'prev,next today',
                 center: 'title',
                 right: 'month,agendaWeek,agendaDay'
             },
             timezone: timezone,
             ignoreTimezone: false,
             events: baseurl + "load_schedule",
             editable: true,
             defaultView: 'agendaWeek',
             firstHour: 8,
             allDayDefault: false
         }

I do have more options, but those should suffice for the purpose of this question.As mentioned in the docs, fullcalendar passes a URL via GET which looks like this:

         mysite.com / my_page / load_schedule ? start = 2014 - 02 - 02 & end = 2014 - 02 - 09 & timezone = Europe % 2FChisinau & _ = 1391660233815 

Then, on the backend I am doing the following to convert fromMYSQL datetime toISO8601

$start = ($event['start']); 
$end = ($event['end']); 
$dateStart = new DateTime($start, new DateTimeZone($timezone)); 
$dateEnd = new DateTime($end, new DateTimeZone($timezone)); 
$dateStart - > setTimezone(new DateTimeZone($timezone)); 
$dateEnd - > setTimezone(new DateTimeZone($timezone)); 
$event['start'] = $dateStart - > format(DateTime::ISO8601); 
$event['end'] = $dateEnd - > format(DateTime::ISO8601); 
$newResult[] = $event;

The $timezone variable holds Europe/Chisinau which was of course passed by fullcalendar itself.

Here is what the above returns back to fullcalendar:

[{"id":"5","start":"2014-02-06T14:10:00+0200","end":"2014-02-06T15:00:00+0200","title":"My title"}]

Everything seems to be correct, but regardless of what I've tried the events show as 2PM.

NOTE This is important, I haven't mentioned this yet but I am passing in a timezone of my choice to the renderSchedule function. So, even though I am located on the East Coast of the US, I would like to be able to pass in a European Timezone and have the calendar render accordingly.

Also, I should point out that I'm using the beta version (2.0) which allows a timezone string to be passed (which I am doing) and uses moments via moment.js

Any idea what I'm doing wrong here?

1个回答



我能够从演示中获得它。 我更新了您的日期格式以包含偏移的冒号。 另外,fullcalendar 1.6.4的最新稳定版本没有时区变量。</ p>

  $('#calendar')。fullCalendar({
editable:true,\ n标题:{
left:“prev,next”,
center:“title”,
right:“month,basicWeek,agendaWeek,basicDay,agendaDay”
},
ignoreTimezone:false,
events :[
{
start:“2014-02-06T14:10:00 + 02:00”,
end:“2014-02-06T15:00:00 + 02:00”,
标题:“ 我的标题“,
allDay:false
}
});
</ code> </ pre>

如果您使用的是Beta版2.0,那么您需要将ignoreTimezone删除为 这不再是一个参数。 </ p>

更新后的答案:</ h3>

事实证明问题是如何在后端处理日期。 以下是我解决这个问题的方法。</ p>

  date_default_timezone_set($ timezone); 
$ timestampStart = strtotime($ mysql_start_date);
$ timestampEnd = strtotime($ mysql_end_date);

$ local_time_start = $ timestampStart + date('Z');
$ local_time_end = $ timestampEnd + date('Z');
$ local_date_start = date('Ymd H:i:s',$ local_time_start);

$ local_date_end = date('Ymd H:i:s',$ local_time_end);

$ event ['start'] = $ local_date_start;
$ event ['end'] = $ local_date_end;
</ code> </ pre>
</ div>

展开原文

原文

I was able to get it to work from the demo. I updated your date format to include colons for the offset. Also the latest stable version of fullcalendar 1.6.4 doesn't have a timezone variable.

$('#calendar').fullCalendar({
        editable: true,
        header : {
            left:"prev,next",
            center:"title",
            right:"month,basicWeek,agendaWeek,basicDay,agendaDay"
            },
        ignoreTimezone: false,
        events: [
        {
            start: "2014-02-06T14:10:00+02:00",
            end:"2014-02-06T15:00:00+02:00",
            title:"My title",
            allDay: false
        }
});

If you are using the beta release 2.0, then you need to remove ignoreTimezone as this is no longer a parameter.

Updated Answer:

It turns out the issue was how the dates were being handled on the backend. Here is how I solved this problem.

date_default_timezone_set($timezone);
            $timestampStart = strtotime($mysql_start_date);
            $timestampEnd = strtotime($mysql_end_date);
            $local_time_start = $timestampStart + date('Z');
            $local_time_end = $timestampEnd + date('Z');
            $local_date_start = date('Y-m-d H:i:s', $local_time_start);
            $local_date_end = date('Y-m-d H:i:s', $local_time_end);

            $event['start'] = $local_date_start;
            $event['end'] = $local_date_end;

doujiao1180
doujiao1180 让我们在聊天中继续讨论
6 年多之前 回复
donglian5309
donglian5309 我不明白的是,无论我在我的目的做什么,似乎我发送到fullcalendar的响应是正确的。 JSON响应具有开始和结束时间,这些时间使用适当的时间偏移进行格式化。 我在这里错过了什么吗?
6 年多之前 回复
dougupang0901
dougupang0901 是的,当我在PHP中使用DateTime :: ISO8601时,偏移量没有冒号,当我使用DateTime :: ATOM时,冒号放在偏移量中。 但是,都不起作用。 这太奇怪了。 我很惊讶没有PHP示例。
6 年多之前 回复
doulongsi1831
doulongsi1831 我只是仔细检查了文档,并且只在事件上指定了timezoneParam。 时区参数应该有效。 你试过在你的补偿中添加“:”吗?
6 年多之前 回复
doulu2029
doulu2029 嗨,感谢所有的跟进,我真的很感激。 我确实看到了那个演示,但是在那个演示中他们使用了“timezone”参数,你还建议我把它改成timezoneParam吗?
6 年多之前 回复
dosin84644
dosin84644 我不认为你可以改变ignoreTimezone的值,因为它在2.0中不存在。 看看arshaw.com/fullcalendar/wiki/Upgrading-to-2。
6 年多之前 回复
dsjj15012
dsjj15012 在这种情况下,ignoreTimezone默认设置为false,您的timezone参数应为“timezoneParam”与“timezone”。 你有没有在arshaw.com/fullcalendar/docs2/timezone/timezone看过这个演示?
6 年多之前 回复
dongzhong2008
dongzhong2008 我正在使用支持时区的beta版本并使用moment.js
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问