尝试获取dayClick()
回调以获取当前日期。相反,无论我做什么,它在return YESTERDAY
看来都是错误的,甚至显示了一周中的错误日期(即,当与日期匹配的实际日期是周六时,它会显示"星期五")。需要注意的一件非常奇怪的事情是,这似乎只发生在我点击"today"
前后的日期(即突出显示的日期)时,有时它会自行更正,有时。。。不
这是我的JS:
(function() {
'use strict';
$(document).ready(function(){
// Full calendar
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: ''
},
dayClick: function(date) {
console.log(date);
}
});
});
})();
还有我的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>VetPro Dashboard</title>
<!-- Style Css-->
<link rel="stylesheet" href="../../vendor/bower_components/fullcalendar/dist/fullcalendar.min.css">
<!-- jQuery -->
<script type="text/javascript" src="../../vendor/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../../vendor/bower_components/moment/min/moment.min.js"></script>
<script type="text/javascript" src="../../vendor/bower_components/fullcalendar/dist/fullcalendar.min.js"></script>
<script type="text/javascript" src="../../assets/javascripts/calendar_scheduler.js"></script>
</head>
<body class="split-background">
<!-- Start Body -->
<div class="container-fluid" id="vetpro-dashboard">
<h1 class="page-header text-center">Dashboard</h1>
<div class="container">
<ul id="tabs" class="text-center col-xs-12 font-mobile-17">
<a href="dashboard_projects.html"><li class="col-xs-2">Projects</li></a>
<li class="col-xs-2 active">Schedule</li>
<a href="dashboard_transactions.html"><li class="col-xs-2">Transactions</li></a>
<a href="dashboard_profile.html"><li class="col-xs-2">Profile</li></a>
<a href="#"><li class="col-xs-2">Support</li></a>
</ul>
</div>
<div class="container container-border" id="dashboard-schedule">
<div class="col-md-6">
<div id="calendar">
</div>
</div>
<div class="col-md-6" id="exceptions">
<div id="scheduler">
<div id="timepicker">
</div>
</div>
</div>
</div>
</div>
<!-- End Body -->
</body>
</html>
最后,当我点击12/4/15(本文发布日期)时显示的控制台日志:
n {_isAMomentObject: true, _isUTC: true, _offset: 0, _locale: R.b, _d: Thu Dec 03 2015 16:00:00 GMT-0800 (Pacific Standard Time)…}
这里怎么了?我可以采取什么措施来确保这种情况在未来不会发生?非常感谢。
试试这个:
dayClick: function(date, jsEvent, view) {
date.format();
}
您可以使用以下方法获取日期:-
dayClick: function(date, jsEvent, view) {
alert('Clicked on: ' + date.format());
alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
alert('Current view: ' + view.name);
}
在jquery fullcalendar中,您将获得上一个日期,您必须对该日期进行一些处理。
由于某种原因,在标题中添加"next"one_answers"prev"按钮可以解决问题。不知道为什么。希望这能帮助将来有这个问题的人。
"I fixed"with:
var startdate = moment( date['date'] );
startdate = startdate.subtract(1, "days");
this.dia = startdate.subtract(-1, "days").toString(); // <-- correct date
用正确的格式修复了这个问题"MM/DD/YYYY";,这与新的Date()构造非常匹配
dayClick: function(date, jsEvent, view) {
date.format("MM/DD/YYYY");
}