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; function App() { const currentDate = new Date(); const currentDay = currentDate.getDay(); const firstDayOfWeek = new Date(currentDate); firstDayOfWeek.setDate(currentDate.getDate() - currentDay); const lastDayOfWeek = new Date(currentDate); lastDayOfWeek.setDate(currentDate.getDate() + (6 - currentDay)); const firstDayString = firstDayOfWeek.toISOString().slice(0, 10); const lastDayString = lastDayOfWeek.toISOString().slice(0, 10); return ( <div className='container'> <h3>React Js Get First and Last Day of the Current Week</h3> <p>First day of the week: {firstDayString}</p> <p>Last day of the week: {lastDayString}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 600px; margin: 0 auto; } </style> </body> </html>