Hello Devs,

In this tutorial, we are going to learn how to display current date and time in react.

Follow this step by step guide given below:




Step 1]


 React Get Current Date Time

import React, { Component } from 'react';
import { render } from 'react-dom';
   
class App extends Component {
  constructor() {
    this.state = {
      currentDateTime: Date().toLocaleString()
    }
  }
  
  render() {
    return (
      <div>
        <p>
          { this.state.currentDateTime }
        </p>
      </div>
    );
  }
}
  
render(<App />, document.getElementById('root'));


Output:

Sun May 24 2020 09:59:56 GMT+0530 (India Standard Time)

 

I hope this example helps you.