0
var Timeframe = React.createClass({
getInitialState: function() {
return {
tfs: getParameterByName('tfs'),
tfe: getParameterByName('tfe')
}
},
formatTime: function(time) {
var full = new Date(time);
console.log(time);
console.log(full);
return (full).toString('dddd, MMMM ,yyyy');
},
render: function() {
return (
<div>Timeframe: {this.formatTime(this.state.tfs)} - {this.formatTime(this.state.tfs)}</div>
);
}
});反应无效日期
我有一个名为getParameterByName的外部js函数,在这种情况下,它将在unix时间返回一个时间。据我所知,Date()对这些数字非常适用,除了React之外,我从来没有遇到任何麻烦。当我在我的反应函数中尝试使用Date时,它将返回无效日期。有人知道为什么会发生这种情况吗?
您是否验证过tfs和tfe设置正确?例如在不调用formatTime的情况下输出它们 – ryanbraganza 2015-02-11 18:32:26
是的,这是工作,只是检查并在控制台中插入新的日期。工作罚款。 – 2015-02-11 18:34:38
getParameterByName返回一个字符串而不是数字吗? – ryanbraganza 2015-02-11 18:39:44