在React中将字符串转换为日期

Ned*_* DN 5 javascript json reactjs

我从JSON对象中以字符串格式检索了一个日期变量,但是直到现在为止我都无法获得经过的时间。

import React from 'react';

export default class Date extends React.Component {
render() {

    console.log(this.props.date); //shows: 2017-01-25T10:18:18Z

    var date = Date.parse(this.props.date.toString());

    console.log(date.getTime());

    return (
        <div >
      </div>
    );
   }
}
Run Code Online (Sandbox Code Playgroud)

Cha*_*ase 5

如果它不是日期对象,只需创建一个新的日期对象。

 var date = new Date(this.props.date); 
 var elapsed = date.geTime(); // Elapsed time in MS
Run Code Online (Sandbox Code Playgroud)

如果只是调用 this.props.date.getTime()