N
N
nikmil2019-08-29 14:40:55
React
nikmil, 2019-08-29 14:40:55

How to make time update in moment.js?

Good afternoon, please tell me how to make it so that the time is updated in real time? I installed moment.js and there, even if you set interval = "1000", the time still does not want to be updated. I read that you need to install moment-timer, but how to connect it correctly? Or is there some other way to solve this problem? (All work is written in React)

import Moment from 'react-moment';

class Player extends React.Component {

    render() {
      const date = new Date();
        return (
          
          <React.Fragment>
                    <div className="time">
                     <div className="img-clm2"><img src={time} alt="time" /></div>
                     <div className="txt"> <Moment  interval={1000} format="HH:mm DD.MM.YYYY" >{date}</Moment> </div>
                   </div>
     
                 
          </React.Fragment>
        )
      }
}

export default Player;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr Muhurov, 2019-08-29
@nikmil

render() {
    return (
      <Moment interval={1000} />
    );
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question