Get Current Date Month Year in React js

Get Current Date Month Year in React js

In this post you can learn how to get current date month year in react js. Sometime you have require to get only date, get only month and get only year in react js. toLocaleDateString() function to you can get current date month year in react js.

Get only current date in react

You can get current date using Date().getDate() function in react js.

Read Also :  Onclick to Get Current Date in React js

Get only current month in react

You can get current month using Date().getMonth() function in react js.

Get only current year in react

You can get current yearusing Date().getYear() function in react js.

Example 1 : Get Current Date Month Year in React js

Index.js

import React from 'react'
import ReactDOM from 'react-dom'

function CDate(){
  const cdate = new Date().toLocaleDateString();
  return(<h3>{cdate}</h3>)
}

ReactDOM.render(<CDate />,document.getElementById("root"));

Example 2 : Get only current date in react

Index.js

import React from 'react'
import ReactDOM from 'react-dom'

function CDate(){
  const cdate = new Date().getDate();
  return(<h3>{cdate}</h3>)
}

ReactDOM.render(<CDate />,document.getElementById("root"));

Example 3 : Get only current month in react

Index.js

import React from 'react'
import ReactDOM from 'react-dom'

function CMonth(){
  const cmonth = new Date().getMonth();
  return(<h3>{cmonth}</h3>)
}

ReactDOM.render(<CMonth />,document.getElementById("root"));

Example 4 : Get only current year in react

Index.js

import React from 'react'
import ReactDOM from 'react-dom'

function CYear(){
  const cyear = new Date().getUTCFullYear();
  return(<h3>{cyear}</h3>)
}

ReactDOM.render(<CYear />,document.getElementById("root"));