假设我正在创建事件起件日期 : 2017-06-14日期: 2017-06-16从时间 : 13:00:00到时间 : 16:00:00
我正确地将它们存储在数据库中。现在一个问题是完整的日历数据应该显示在时间13:00:00到16:00:00之间,而不是在2017-06-15上显示一整天。有什么错误吗?我的代码是
显示数据的完整日历:
var id=$("#hidden_id").val();
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
header: {
left: '',
center: 'prev title next',
right: ''
},
/*
loading: function (bool) {
$("#loading_div").show();
},
*/
defaultDate: "<?php echo date('Y-m-d');?>",
navLinks: true, // can click day/week names to navigate views
editable: false,
events: "json_rate-info/"+id,
allDay: true,
selectable: true,
selectHelper: true,
});
获取数据功能
public function GetJsonRateInfo($rate_id)
{
$json = array();
$start=$_REQUEST['start'];
$end=$_REQUEST['end'];
if($start != '' && $end != '')
{
$where="(from_date BETWEEN '$start' and '$end') or (to_date BETWEEN '$start' and '$end')";
$finalArray=[];
$json=$this->Rates_model->getAnyData($where);
/*echo '<pre>';
print_r($json);
die();*/
if(!empty($json))
{
foreach ($json as $key => $js) {
$finalArray[$key]['id']= $js->id;
$finalArray[$key]['start']= date('Y-m-d',strtotime($js->from_date))."T".$js->from_time;
$finalArray[$key]['end'] = date('Y-m-d',strtotime($js->to_date))."T".$js->to_time;
if(!empty($js->rate_per_hour) && !empty($js->rate_per_mile))
{
$fullTitle="Per Hour: ".$js->rate_per_hour.",Per Mile: ".$js->rate_per_mile;
}
elseif(!empty($js->rate_per_hour) && empty($js->rate_per_mile)){
$fullTitle="Per Hour: ".$js->rate_per_hour;
}
elseif(empty($js->rate_per_hour) && !empty($js->rate_per_mile)){
$fullTitle="Per Mile: ".$js->rate_per_mile;
}
$finalArray[$key]['title']=$fullTitle;
}
echo json_encode($finalArray);
}
}
}
我的 Json 数据 :
[{"id":"1","start":"2017-06-14T13:00:00","end":"2017-06-15T16:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"}]
在您的示例中,您有一个事件,该事件从 14 日的 13:00 开始,到 15 日的 16:00 结束。因此,该事件将涵盖该事件之间的所有时间(1 天 + 3 小时(。这是日历上完全正确的行为 - 请参阅它在此处工作:https://jsfiddle.net/4bznpxc5/1 。
如果要在 3 个不同的日子重复相同的时间,则必须在 JSON 源中输出 3 个单独的事件对象,如下所示:
[
{"id":"1","start":"2017-06-14T13:00:00","end":"2017-06-14T16:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"},
{"id":"2","start":"2017-06-15T13:00:00","end":"2017-06-15T16:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"},
{"id":"3","start":"2017-06-16T13:00:00","end":"2017-06-16T16:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"}
]