对象作为 React 子对象无效

fri*_*sk0 3 reactjs

我有一个从 unix 时间戳计算日期的函数

_getTime(time) {
var dateTime = new Date(time*1000);

console.log(dateTime);
return dateTime

  },
Run Code Online (Sandbox Code Playgroud)

该函数用于此

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>
          );
    );
},
Run Code Online (Sandbox Code Playgroud)

这将返回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应用程序.

我知道有相同错误消息的问题,但我似乎无法找到解决我的问题的方法。

Faz*_*sel 6

普通的javascript:

_getTime(time) {
    var dateTime = new Date(time*1000).toString();    
    console.log(dateTime);
    return dateTime    
 },
Run Code Online (Sandbox Code Playgroud)

使用moment.js

_getTime(time) {
    var dateTime = moment(time*1000).format('YYYY-MM-DD HH:mm:ss');    
    console.log(dateTime);
    return dateTime    
 },
Run Code Online (Sandbox Code Playgroud)