Fullcalendar 将纪元时间值返回到数据库
Fullcalendar returning epoch time values to the database
我正在为我的 page.When 使用全日历 jquery 插件我正在使用全日历插件插入新事件..,它返回我的纪元时间值而不是 UTC 时间日期值。
下面是点击日期将新数据插入数据库的代码。
calendar.fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventSources: [
{
url: '/v1/calendar/',
type: 'GET',
dataType:'json',
},
calendar.fullCalendar( 'addEventSource', response )
],
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
bootbox.prompt("New Event Title:", function(title) {
var people_id=1;
//var title=event.title;
//var start=event.start;
//var end=event.end;
if (title !== null) {
calendar.fullCalendar('renderEvent',
{
people_id:people_id,
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
$.ajax({
url: '/v1/calendar',
data: 'people_id='+people_id+'&title='+title+'&start='+start+'&end='+end,
type: 'POST',
dataType: 'json',
success: function(response){
bootbox.alert("Event Created!");
console.log(response);
},
error: function(e){
console.log(e.responseText);
}
});
}
});
事件已成功添加到数据库中...但时间为纪元格式。
我得到的控制台响应如下:
{people_id: "1", evt_description: "testing", date1: "1431388800000", date2: "1431475200000", event_id: 4}
我在后端使用 laravel 框架 我在下面附加了我的 CalendarController:
<?php
class CalendarController extends \BaseController {
/**
* Display a listing of calendar
*
* @return Response
*/
public function index()
{
$event = DB::table('events')
->leftJoin('people','people.people_id','=','events.people_id')
->leftJoin('people_roles','people_roles.people_id','=','events.people_id')
->get(array('events.people_id','events.event_id','events.evt_description','events.date1','events.date2','events.time'));
//return View::make('people.show', compact('address'));
//return Response::json($event);
$id=array();
$title=array();
$start=array();
$end=array();
$i=0;
foreach ($event as $events)
{
$id[$i]=$events->event_id;
$title[$i]=$events->evt_description;
$start[$i]=$events->date1;
$end[$i]=$events->date2;
$i++;
}
return Response::json(array('id'=>$id,'title'=>$title,'start'=>$start,'end'=>$end));
}
/**
* Show the form for creating a new calendar
*
* @return Response
*/
public function create()
{
return View::make('calendar.create');
}
/**
* Store a newly created calendar in storage.
*
* @return Response
*/
public function store()
{
$events= Input::get('type');
$events= new Events;
$events->people_id = Input::get('people_id');
$events->evt_description =Input::get('title');
$events->date1 =Input::get('start');
$events->date2 =Input::get('end');
//$events->time =Input::get('time');
$events->save();
return Response::json($events);
//return Redirect::route('calendar.index');
}
/**
* Display the specified calendar.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$calendar = Calendar::findOrFail($id);
return View::make('calendar.show', compact('calendar'));
}
/**
* Show the form for editing the specified calendar.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$calendar = Calendar::find($id);
return View::make('calendar.edit', compact('calendar'));
}
/**
* Update the specified calendar in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//$type=Input::get('type');
$event_id= Input::get('event_id');
$title= Input::get('title');
$roles = DB::table('events')
->where('event_id','=',$event_id )
->update(array('evt_description' => $title));
return Response::json(array('id'=>$event_id,'title'=>$title));
}
/**
* Remove the specified calendar from storage.
*
* @param int $id
* @return Response
*/
public function destroy()
{
// Calendar::destroy($id);
$event_id= Input::get('eventid');
DB::table('events')->where('event_id','=',$event_id)->delete();
return Response::json($event_id);
// return Redirect::route('calendar.index');
}
}
只需使用 Carbon 来处理控制器上的日期。在您的商店方法中,而不是
$events->date1 =Input::get('start');
$events->date2 =Input::get('end');
使用
$events->date1 = Carbon::createFromTimeStamp(Input::get('start'))->toDateTimeString();
$events->date2 = Carbon::createFromTimeStamp(Input::get('end'))->toDateTimeString();
确保在您的日历控制器上使用该包。示例:
<?php
use Carbon\Carbon;
class CalendarController extends \BaseController {
不需要安装,因为它已经是Laravel的依赖项。
试试这个
$newstrt=substr($start_day,0,10);
$newend=substr($end_day,0,10);
$events->start= date("Y-m-d",$newstrt);
$events->end= date("Y-m-d", $newend);
$events->save();
我正在为我的 page.When 使用全日历 jquery 插件我正在使用全日历插件插入新事件..,它返回我的纪元时间值而不是 UTC 时间日期值。
下面是点击日期将新数据插入数据库的代码。
calendar.fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventSources: [
{
url: '/v1/calendar/',
type: 'GET',
dataType:'json',
},
calendar.fullCalendar( 'addEventSource', response )
],
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
bootbox.prompt("New Event Title:", function(title) {
var people_id=1;
//var title=event.title;
//var start=event.start;
//var end=event.end;
if (title !== null) {
calendar.fullCalendar('renderEvent',
{
people_id:people_id,
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
$.ajax({
url: '/v1/calendar',
data: 'people_id='+people_id+'&title='+title+'&start='+start+'&end='+end,
type: 'POST',
dataType: 'json',
success: function(response){
bootbox.alert("Event Created!");
console.log(response);
},
error: function(e){
console.log(e.responseText);
}
});
}
});
事件已成功添加到数据库中...但时间为纪元格式。
我得到的控制台响应如下:
{people_id: "1", evt_description: "testing", date1: "1431388800000", date2: "1431475200000", event_id: 4}
我在后端使用 laravel 框架 我在下面附加了我的 CalendarController:
<?php
class CalendarController extends \BaseController {
/**
* Display a listing of calendar
*
* @return Response
*/
public function index()
{
$event = DB::table('events')
->leftJoin('people','people.people_id','=','events.people_id')
->leftJoin('people_roles','people_roles.people_id','=','events.people_id')
->get(array('events.people_id','events.event_id','events.evt_description','events.date1','events.date2','events.time'));
//return View::make('people.show', compact('address'));
//return Response::json($event);
$id=array();
$title=array();
$start=array();
$end=array();
$i=0;
foreach ($event as $events)
{
$id[$i]=$events->event_id;
$title[$i]=$events->evt_description;
$start[$i]=$events->date1;
$end[$i]=$events->date2;
$i++;
}
return Response::json(array('id'=>$id,'title'=>$title,'start'=>$start,'end'=>$end));
}
/**
* Show the form for creating a new calendar
*
* @return Response
*/
public function create()
{
return View::make('calendar.create');
}
/**
* Store a newly created calendar in storage.
*
* @return Response
*/
public function store()
{
$events= Input::get('type');
$events= new Events;
$events->people_id = Input::get('people_id');
$events->evt_description =Input::get('title');
$events->date1 =Input::get('start');
$events->date2 =Input::get('end');
//$events->time =Input::get('time');
$events->save();
return Response::json($events);
//return Redirect::route('calendar.index');
}
/**
* Display the specified calendar.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$calendar = Calendar::findOrFail($id);
return View::make('calendar.show', compact('calendar'));
}
/**
* Show the form for editing the specified calendar.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$calendar = Calendar::find($id);
return View::make('calendar.edit', compact('calendar'));
}
/**
* Update the specified calendar in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//$type=Input::get('type');
$event_id= Input::get('event_id');
$title= Input::get('title');
$roles = DB::table('events')
->where('event_id','=',$event_id )
->update(array('evt_description' => $title));
return Response::json(array('id'=>$event_id,'title'=>$title));
}
/**
* Remove the specified calendar from storage.
*
* @param int $id
* @return Response
*/
public function destroy()
{
// Calendar::destroy($id);
$event_id= Input::get('eventid');
DB::table('events')->where('event_id','=',$event_id)->delete();
return Response::json($event_id);
// return Redirect::route('calendar.index');
}
}
只需使用 Carbon 来处理控制器上的日期。在您的商店方法中,而不是
$events->date1 =Input::get('start');
$events->date2 =Input::get('end');
使用
$events->date1 = Carbon::createFromTimeStamp(Input::get('start'))->toDateTimeString();
$events->date2 = Carbon::createFromTimeStamp(Input::get('end'))->toDateTimeString();
确保在您的日历控制器上使用该包。示例:
<?php
use Carbon\Carbon;
class CalendarController extends \BaseController {
不需要安装,因为它已经是Laravel的依赖项。
试试这个
$newstrt=substr($start_day,0,10);
$newend=substr($end_day,0,10);
$events->start= date("Y-m-d",$newstrt);
$events->end= date("Y-m-d", $newend);
$events->save();