How to Get Current Date in React JS?

Sep 23, 2022 . Admin

Hey,

Today, I would like to show you how to get current date in react js. you can understand a concept of react js get current date. I explained simply about react js get current date yyyy-mm-dd. I would like to share with you react.js get current date. Alright, let’s dive into the steps.

In this example, we will use "Date" object to get current date in react js app. we will use "getFullYear()", "getMonth()" and "today.getDate()" to getting current format.

So, let's see follow the below step to create simple example.

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app react-axios-example
Step 2: Update App.js Component

Here, we will call two apis for getting posts and another for deleting post using axios request.

src/App.js
import './App.css';

function App() {
  
  let today = new Date();
  let date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();

  return (
    <div className="App">
      <h1>How to Get Current Date in React JS? - MyWebtuts.com</h1>
      <h2>Your Current Date is: </h2>
      <h4>{date}</h4>
    </div>
  );
}

export default App;
Step 3: Run React JS App

In the last step run your project using bellow command.

npm start
Output:

I hope it can help you...

#React JS