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 { useState } = React; const App = () => { const [firstDay, setFirstDay] = useState(null); const [lastDay, setLastDay] = useState(null); const handleButtonClick = () => { const date = new Date(); const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1); const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0); setFirstDay(firstDayOfMonth); setLastDay(lastDayOfMonth); }; return ( <div className='container'> <h3>React Get Current Month start Date and End Date</h3> <button onClick={handleButtonClick}>Get Current Month Dates</button> <p>Start Date: {firstDay && firstDay.toLocaleDateString('en-GB')}</p> <p>End Date: {lastDay && lastDay.toLocaleDateString('en-GB')}</p> </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> </body> </html>