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, useEffect } = React; function App() { const [currentDate, setCurrentDate] = useState(new Date()); useEffect(() => { // Function to subtract days from a date const subtractDaysFromDate = (date, days) => { const result = new Date(date); result.setDate(date.getDate() - days); return result; }; // Get yesterday's date const yesterdayDate = subtractDaysFromDate(currentDate, 1); // Update the state with yesterday's date setCurrentDate(yesterdayDate); }, []); return ( <div className='container'> <h3 className='title'>React Subtract Days from Date</h3> <p className='date'>Yesterday Date: {currentDate.toDateString()}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Styles for the title */ .title { font-size: 24px; color: #333; margin-bottom: 10px; } /* Styles for the date paragraph */ .date { font-size: 18px; color: #555; } </style> </body> </html>