我有一个从unix时间戳
计算日期的函数_getTime(time) {
var dateTime = new Date(time*1000);
console.log(dateTime);
return dateTime
},
该功能在此
中使用render: function() {
return (
{this.state.daily.map(day => {
return (
<div key={day.time} className="key col-md-12">
<div className="col-md-3">{this._getTime(day.time)}</div>
</div>
);
);
},
这会返回Invariant Violation: Objects are not valid as a React child (found: Thu Oct 20 2016 00:00:00 GMT+0200 (CEST)). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of
应用.
我知道有相同错误消息的问题,但我似乎无法找到解决问题的方法。
答案 0 :(得分:3)
普通javascript:
_getTime(time) {
var dateTime = new Date(time*1000).toString();
console.log(dateTime);
return dateTime
},
使用moment.js
_getTime(time) {
var dateTime = moment(time*1000).format('YYYY-MM-DD HH:mm:ss');
console.log(dateTime);
return dateTime
},