export default class index extends Component {
constructor() {
super();
this.state = { date: new Date() };
}
componentWillMount() {
this.timer = setInterval(() => { this.setState({ date: new Date() }) }, 1000);
}
componentWillUnmount() {
clearInterval(this.timer);
this.timer = null;
}
render() {
let t = this.state.date;
let year = t.getFullYear();
let month = t.getMonth() + 1;
let day = t.getDay() + 1;
let hour = ((t.getHours() < 10) ? "0" : "") + t.getHours();
let minutes = ((t.getMinutes() < 10) ? "0" : "") + t.getMinutes();
let ifnoon = ‘ ‘ + ((t.getHours() < 12) ? "上午" : "下午") + ‘ ‘;
return (
<div className="header">
<Row className="breadcrumb">
<Col span={4} className="breadcrumb-title">首页</Col>
<Col span={20} className="weather">
<span className="date">{year + ‘/‘ + month + ‘/‘ + day + ifnoon + hour + ‘:‘ + minutes}</span>
</Col>
</Row>
</div>
)
}
}
原文地址:https://www.cnblogs.com/toMe-studio/p/11465235.html