screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useEffect, useState } = React; const App = () => { const [currentDate, setCurrentDate] = useState(""); useEffect(() => { const currentDateObj = new Date(); const month = currentDateObj.getMonth() + 1; const year = currentDateObj.getFullYear(); setCurrentDate(`${month}/${year}`); }, []); return ( <div className="container"> <h1>React Js Get Current Month and Year</h1> <p>Current month and year: {currentDate}</p> </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> </body> </html>