Answers for "how to get current date in react js"

0

how to get current date in react js

export function getCurrentDate(separator=''){

let newDate = new Date()
let date = newDate.getDate();
let month = newDate.getMonth() + 1;
let year = newDate.getFullYear();

return `${year}${separator}${month<10?`0${month}`:`${month}`}${separator}${date}`
}
Posted by: Guest on March-10-2021
0

displaying the date react

import React from "react";

export default class App extends React.Component {
  state = {
    date: ""
  };

  componentDidMount() {
    this.getDate();
  }

  getDate = () => {
    var date = new Date().toDateString();
    this.setState({ date });
  };

  render() {
    const { date } = this.state;

    return <div>{date}</div>;
  }
}
}

export default App;
Posted by: Guest on August-17-2020

Code answers related to "how to get current date in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language