React
HTML
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
.done {
color: rgba(0, 0, 0, 0.3);
text-decoration: line-through;
}
input {
margin-right: 5px;
}
React
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
datetime: new Date()
}
}
componentDidMount() {
setInterval(() => {
this.setState({datetime: new Date()})
}, 1000);
}
getDateTime() {
let now = new Date();
let year = now.getFullYear();
let month = now.getMonth()+1;
let day = now.getDate();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
if(month.toString().length === 1) {
month = '0'+month;
}
if(day.toString().length === 1) {
day = '0'+day;
}
if(hour.toString().length === 1) {
hour = '0'+hour;
}
if(minute.toString().length === 1) {
minute = '0'+minute;
}
if(second.toString().length === 1) {
second = '0'+second;
}
var dateTime = hour+':'+minute+':'+second;
return dateTime;
}
render() {
return (
<div>
<h2>The time is {this.getDateTime()}</h2>
</div>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))