Created
March 19, 2017 18:38
-
-
Save casprwang/a7b0f70edb83ce2a0ef045fed769d601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import moment from 'moment'; | |
import './Timer.css' | |
class Timer extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
now: moment(new Date()), | |
} | |
} | |
componentDidMount() { | |
this.timerID = setInterval( | |
() => this.tick(), | |
1000, | |
); | |
} | |
componentWillUnmount() { | |
clearInterval(this.timerID); | |
} | |
tick() { | |
this.setState({ | |
now: moment(new Date()), | |
}); | |
} | |
render() { | |
let metTime = moment('20170307T180000') | |
let diff = this.state.now - metTime | |
return ( | |
<div className="container"> | |
<div className="counter"> | |
<div className="title">Mini&Song<br></br>been together for</div> | |
<div className="inner"> | |
<div className="days-title">Days | |
<div className="days">{ moment.duration(diff/1000, 'seconds')._data.days }</div> | |
</div> | |
<div className="hours-title">Hours | |
<div className="hours">{ moment.duration(diff/1000, 'seconds')._data.hours }</div> | |
</div> | |
<div className="minutes-title">Minutes | |
<div className="minutes">{ moment.duration(diff/1000, 'seconds')._data.minutes }</div> | |
</div> | |
<div className="seconds-title">Seconds | |
<div className="seconds">{ moment.duration(diff/1000, 'seconds')._data.seconds }</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default Timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment