我在使用fullCalendar时遇到了问题。依赖库时刻.js将输出以下错误。
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: 1, _f: undefined, _strict: undefined, _locale: [object Object]
我已经在SO上查看了这里,这似乎是与事件通过日期格式相关的错误。我已经检查了提取数据的数据库表,存储的格式是这样的 DATEY-m-d
所以每个事件日期都类似于2018-09-19
.有没有办法解决这个问题?这很奇怪,因为我在其他项目中使用相同的插件,它没有给我此错误,并且存储的数据与设置为 db 列的格式相同DATE
.
事件的 PHP 代码
$events = array();
$stmt = $db->prepare('SELECT * FROM matches');
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $result){
$events[] = array(
'id' => $result['id'],
'title' => $result['competition'],
'start' => DateTime::createFromFormat('Y-m-d' ,$result['matchDay']),
'end' => DateTime::createFromFormat('Y-m-d' ,$result['matchDay'])
);
}
echo json_encode($events);
?>
在这一行中
'title' => DateTime::createFromFormat('Y-m-d' ,$result['competition']),
'end' => DateTime::createFromFormat('Y-m-d' ,$result['matchDay'])
您告诉它使用这种"Y-m-d"格式创建一个日期,请尝试给
'Y-m-d H:i:s' format and see what happens