ReactJs Get Current Date Time


We can use native Javascript date function to get the current and time in ReactJs. Here in this tutorial, we are going to explain how you can use javascript dete function to get the current date and time. You can also use our online editor to edit and run the code online.


ReactJs Get Current Date Time JavaScript Example

You can get the current date time in YYYY-MM-DD H:i:s Format simply as below-

Example:

<script>
function MyFunction() {
  var tempDate = new Date();
  var date = tempDate.getFullYear() + '-' + (tempDate.getMonth()+1) + '-' + tempDate.getDate() +' '+ tempDate.getHours()+':'+ tempDate.getMinutes()+':'+ tempDate.getSeconds();
  const currDate = "Current Date= "+date;
  return (
    <p>{currDate}</p>
  );
}
ReactDOM.render(
  <MyFunction />,
  document.getElementById('root')
);


</script>

Try it »

Output of above example-

ReactJs Get Current Date Time

Advertisements

Add Comment

📖 Read More