【发布时间】:2019-05-08 08:26:09
【问题描述】:
我的 react 应用程序需要最近 12 小时的数组,但到目前为止我只有 2 个,而且我正在以最乏味的方式进行操作。
这是我当前有效的代码:
class Example extends Component {
constructor() {
super();
this.now = new Date();
this.hrAgo = new Date(this.now-3600000).toISOString();
this.twoHrsAgo = new Date(this.now-2*3600000).toISOString();
this.state = {
timeData: [this.twoHrsAgo,this.hrAgo,this.now.toISOString()]
}
}
componentDidMount() {
console.log("timeData: ",this.state.timeData);
};
/// other function below
在我的控制台中显示如下内容:
["2019-05-08T06:19:41.744Z", "2019-05-08T07:19:41.744Z", "2019-05-08T08:19:41.744Z"]
如何以更好的方式获得过去 12 小时?
【问题讨论】:
标签: javascript arrays reactjs date