其他分享
首页 > 其他分享> > React时间转换为具体的年月日上午下午

React时间转换为具体的年月日上午下午

作者:互联网

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> ) } }

标签:转换,getMinutes,getHours,timer,month,React,let,date,年月日
来源: https://www.cnblogs.com/toMe-studio/p/11465235.html