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 [initialDate, setInitialDate] = useState(new Date()); const [hoursToAdd, setHoursToAdd] = useState(1); const handleAddHours = () => { const newDate = new Date(initialDate); newDate.setHours(newDate.getHours() + hoursToAdd); setInitialDate(newDate); }; return ( <div className='container'> <h1 className='title'>React js Add Hours to a Date</h1> <div> <p className='date-paragraph'>Initial Date: {initialDate.toString()}</p> <p className='hours-paragraph'>Hours to Add: {hoursToAdd}</p> <input className='hours-input' type="number" value={hoursToAdd} onChange={(e) => setHoursToAdd(parseInt(e.target.value, 10))} /> <button className='add-hours-button' onClick={handleAddHours}>Add Hours</button> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { margin: 0 auto; width: 600px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } .title { font-size: 24px; text-align: center; color: #333; margin-bottom: 20px; } .date-paragraph, .hours-paragraph { font-size: 18px; color: #555; margin-bottom: 10px; } .hours-input { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; box-sizing: border-box; } .hours-input:focus { outline: none; border-color: #007bff; } .add-hours-button { display: block; width: 100%; padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.2s; } .add-hours-button:hover { background-color: #0056b3; } </style> </body> </html>