github.com/stampzilla/stampzilla-go@v2.0.0-rc9+incompatible/nodes/stampzilla-magicmirror/web/src/routes/home/Clock.js (about)

     1  import React from 'react'
     2  import moment from 'moment'
     3  
     4  class Clock extends React.Component {
     5    constructor(props) {
     6      super(props)
     7      this.clock = React.createRef()
     8      this.seconds = React.createRef()
     9      this.date = React.createRef()
    10    }
    11  
    12    componentDidMount() {
    13      const updateClock = () => {
    14        this.clock.current.innerHTML = moment().format('HH:mm')
    15        this.seconds.current.innerHTML = moment().format('ss')
    16        this.date.current.innerHTML = moment().format('dddd - D MMMM')
    17      }
    18      updateClock()
    19      this.clockInterval = setInterval(updateClock, 1000)
    20    }
    21  
    22    componentWillUnmount() {
    23      clearTimeout(this.clockInterval)
    24    }
    25  
    26    render() {
    27      return (
    28        <React.Fragment>
    29          <div className="clock">
    30            <div ref={this.clock}>00:00</div>
    31            <div className="seconds" ref={this.seconds}>
    32              00
    33            </div>
    34          </div>
    35          <div className="date" ref={this.date}>
    36            -
    37          </div>
    38        </React.Fragment>
    39      )
    40    }
    41  }
    42  
    43  export default Clock