我在fullCalendar方面遇到问题。依赖库moment.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]
我在这里查看过,看来与事件通过日期格式有关的错误。我检查了提取数据的数据库表,并且存储的格式为Y-m-d
这样的DATE,因此每个事件日期都类似于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);
?>
答案 0 :(得分:1)
在此行
'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