how toget current date and time react code example
Example 1: 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}`
}
Example 2: react current date and time command
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'));