Output the current date in a customizable format with this component. Easily add formatted dates to your JavaScript projects, saving time and manual effort.
Body
export class DisplayDate extends React.Component {
constructor() {
super();
var today = new Date(),
date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
this.state = {
date: date
};
}
render() {
return (
<h2>
{this.state.date}
</h2>
);
}
}
Tags: datetime, react js, current date and time, new date
1 Replies