[英]Get only seconds from the current date in React.Js component
嘿,我只想从当前日期中提取秒数,但我有点被屏蔽了
这是我的组件,它只返回整个日期:
class Clock extends Component {
constructor(props) {
super(props);
this.state = {
time: new Date().toLocaleString()
};
}
componentDidMount() {
this.intervalID = setInterval(
() => this.tick(),
1000
);
}
componentWillUnmount() {
clearInterval(this.intervalID);
}
tick() {
this.setState({
time: new Date().toLocaleString()
});
}
render() {
return (
<div>{this.state.time}.</div>
);
}
}
export default Clock;
constructor(props) {
super(props);
this.state = {
time: new Date().getSeconds()
};
}
您可以使用getSeconds();
日期 object 上的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.