1export function getCurrentDate(separator=''){
2
3let newDate = new Date()
4let date = newDate.getDate();
5let month = newDate.getMonth() + 1;
6let year = newDate.getFullYear();
7
8return `${year}${separator}${month<10?`0${month}`:`${month}`}${separator}${date}`
9}
1import React from "react";
2
3export default class App extends React.Component {
4 state = {
5 date: ""
6 };
7
8 componentDidMount() {
9 this.getDate();
10 }
11
12 getDate = () => {
13 var date = new Date().toDateString();
14 this.setState({ date });
15 };
16
17 render() {
18 const { date } = this.state;
19
20 return <div>{date}</div>;
21 }
22}
23}
24
25export default App;