我已经看了所有的例子,我不明白为什么FullCalendar不会为我的事件显示正确的时间。对于每个事件,它只列出12a,而不是实际时间。有人能看看我下面的代码,让我知道我做错了什么吗。
JavaScript
jQuery('#calendar').fullCalendar({
allDayDefault: false,
disableDragging: true,
eventSources: [{
events: function(start, end, callback) {
var month = end.getMonth();
month = ('0' +month).slice(-2)
if(month == '0')
{
var year = start.getFullYear(); month = '12';
}
else
var year = end.getFullYear();
var new_url = "<?php echo get_bloginfo('siteurl').'/json-events.php?month='; ?>" + month + "&year="+year;
if( new_url != current_url ){
jQuery.ajax({
url: new_url,
dataType: 'json',
type: 'POST',
success: function( response ) {
current_url = new_url;
user_events = response;
callback(response);
}
});
}else{
callback(user_events);
}
}
}],
theme: true,
header: {
left: 'prev,next',
center: 'title',
right: ''
},
editable: true,
eventRender: function(event, element) {
element.qtip({
content: event.description
});
},
PHP
require_once("includes/classService.php");
$classService = new MBClassService();
require_once("includes/clientService.php");
$classClient = new MBClientService();
session_start();
function cmp($a, $b) {
$expA = explode('T',$a->StartDateTime);
$startTimesA = strtotime($expA[1]).' ';
$expB = explode('T',$b->StartDateTime);
$startTimesB = strtotime($expB[1]);
return (strcmp ($startTimesA,$startTimesB));
}
$time = '';
$currentYr = $_GET['year'];
$currentDy = '01';
$currentMonth = $_GET['month'];
$k = 0;
$startDate = $currentYr.'-'.$currentMonth.'-'.$currentDy;
$lastDay = date('t',strtotime($startDate));
$endofDate = $currentYr.'-'.$currentMonth.'-'.$lastDay;
$recordOfClientAddClass = $classClient->GetClientSchedule($_SESSION['ClientId'],$startDate,$endofDate);
$bookClassArray = array();
for($k = 0; $k < count($recordOfClientAddClass); $k++) {
$bookClassArray[] = $recordOfClientAddClass[$k]->ClassID;
}
for( $j = 1; $j <= $lastDay; $j++ ) {
$days = sprintf("%02s", $j);
$months = sprintf("%02s", $currentMonth);
$currentYr = date('Y');
$start = $currentYr.'-'.$months.'-'.$days.' 00:00:00';
$ends = $currentYr.'-'.$months.'-'.$days.' 23:59:59';
$classesList = $classService->GetClasses(array(), array(), array(), array(), $ends, $ends);
//echo "<pre>"; print_r($classesList);
if(!empty($classesList[0])) {
uasort($classesList, 'cmp');
$classesList = array_values($classesList);
for($k = 0; $k < count($classesList); $k++ ) {
$exp = explode('T',$classesList[$k]->StartDateTime);
$startDateOfClass = $exp[0];
$startTime = $exp[1];
$reformatted_stime = date('g:i a',strtotime($startTime));
$endTime = end(explode('T',$classesList[$k]->EndDateTime));
$t1 = strtotime($startTime);
$t2 = strtotime($endTime);
$delta_T = ($t2 - $t1);
$hours = round((($delta_T % 604800) % 86400) / 3600, 2);
$minutes = round(((($delta_T % 604800) % 86400) % 3600) / 60, 2);
$seconds = round((((($delta_T % 604800) % 86400) % 3600) % 60), 2);
if($hours)
$time .= $hours ." hour " ;
if($minutes)
$time .= $minutes ." Minutes " ;
if($seconds)
$time .= $seconds ." Second " ;
$reformatted_etime = date('g:i a',strtotime($endTime));
if(time() < strtotime($startDateOfClass) && !in_array($classesList[$k]->ID,$bookClassArray))
$url = $classesList[$k]->ID."&".$startDateOfClass."";
else
$url = "";
if(in_array($classesList[$k]->ID,$bookClassArray))
$register = "Already Registered!";
else
$register = "";
$description = '';
if($register != "")
$description .= '<strong style="color:#64C063;">'.$register.'</strong><br>';
$description .= '<strong>Class Name:</strong> '.$classesList[$k]->ClassDescription->Name.'<br> <strong>Teacher:</strong> '.$classesList[$k]->Staff->Name.'<br> <strong>Duration:</strong> '.$time.
'<br> <strong>Time:</strong> '.$reformatted_stime.' To ' .$reformatted_etime."";
if($url) {
$jsonFirstArry[] = array(
'title' => $classesList[$k]->ClassDescription->Name,
'start' => "$currentYr-$months-$days",
'url' => $url,
'className' => 'clickTip',
'description' => "$description"
);
} else {
$jsonFirstArry[] = array(
'title' => $classesList[$k]->ClassDescription->Name,
'start' => "$currentYr-$months-$days",
'className' => 'clickTip',
'description' => "$description"
);
}
$time = '';
}
}
}
echo json_encode($jsonFirstArry);
?>
谢谢
这是FullCalendar的默认时间格式。您需要查看timeFormat文档以了解如何实现更改的详细信息,以及formatDate文档以了解时间格式如何工作的详细信息。
作为一个例子和对特定问题的快速解决方案,如果您要指定。。。
timeFormat: 'h:mmtt'
在日历对象中,在指定事件源和主题的同一级别,应该显示完整的"am"或"pm"。在这种格式下,7pm将显示为"7:00pm"。