我想在react native应用程序中像时钟一样显示当前时间(MM/DD/YY hh:MM:ss),并每秒钟更新一次,我try 使用new Date()并将其设置为状态,但除非刷新页面,否则时间不会更新.
state = {
curTime: null,
}
render(){
setInterval(function(){this.setState({curTime: new Date().toLocaleString()});}.bind(this), 1000);
return (
<View>
<Text style={headerStyle.marginBottom15}>Date: {this.state.curTime}</Text>
</View>
);
}