我正在使用此代码将预订插入数据库。
日期选择器
<script type='text/javascript'>
$(document).ready(function() {
$('#dp1, #dp2').datepicker({
autoclose: true,
format: "yyyy-mm-dd"
});
});
</script>
SQL
<?php
session_start();
$dbh = new PDO('mysql:host=localhost;dbname=calendar', 'user', 'pass');
$stmt = $dbh->prepare("INSERT INTO bookings (forename, surname, badge, colour, start, end) VALUES (:forename, :surname, :badge, :colour, STR_TO_DATE(:dp1,'%Y-%m-%d'), STR_TO_DATE(:dp2,'%Y-%m-%d'))");
foreach ($_POST as $key => $value) {
$stmt->bindParam("$key", $_POST[$key]);
}
$stmt->execute();
header("Location: /");
?>
SQL 表
mysql> SELECT * FROM bookings;
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
| id | forename | surname | badge | colour | start | end | timestamp |
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
| 1 | John | Doe | 1 | black | 2014-10-27 00:00:00 | 2014-10-31 00:00:00 | 2014-10-21 13:11:50 |
+----+----------+---------+-------+--------+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
这是周一至周五的预订,但显示为周一至周四。
SQL查询
<?php
$dbh = new PDO('mysql:host=localhost;dbname=calendar', 'user', 'pass');
$stmt = $dbh->prepare("SELECT * FROM bookings");
$stmt->execute();
$return_array = array();
$event_array;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$event_array = array();
$event_array['id'] = $row['id'];
$event_array['title'] = $row['forename'] ." ". $row['surname'];
$event_array['start'] = $row['start'];
$event_array['end'] = $row['end'];
$event_array['allDay'] = true;
$event_array['className'] = $row['colour'];
array_push($return_array, $event_array);
}
echo json_encode($return_array);
?>
完整日历
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
eventSources: [
{
url: 'data.php',
type: 'POST'
}
]
})
});
</script>
问题
例如,如果我选择开始日期为星期一,结束日期为星期五,则日历会显示从星期一开始到星期四结束的预订,而不是星期五。
我该如何解决这个问题?
最佳答案
发生这种情况是因为事件数组中的 end
是独占的。
另请参阅文档:http://fullcalendar.io/docs/event_data/Event_Object/
The exclusive date/time an event ends. Optional.
A Moment-ish input, like an ISO8601 string. Throughout the API this will become a real Moment object.
It is the moment immediately after the event has ended. For example, if the last full day of an event is Thursday, the exclusive end of the event will be 00:00:00 on Friday!
关于jquery - DatePicker 和 FullCalendar 总是少一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26485913/