FullCalendar不显示正确的时间

时间:2014-04-25 16:42:31

标签: javascript php jquery fullcalendar

我查看了所有示例,但我无法弄清楚为什么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); 
?>

。 谢谢!

1 个答案:

答案 0 :(得分:0)

这是FullCalendar的默认时间格式。您需要查看timeFormat documentation以获取有关如何对其进行更改的详细信息,并formatDate documentation查看有关时间格式如何工作的详细信息。

作为您的具体问题的示例和快速解决方法,如果您要指定...

timeFormat: 'h:mmtt'

...在您的日历对象中,在您指定事件源和主题的同一级别,应显示完整的“am”或“pm”。在此格式下,晚上7点将显示“晚上7点”。