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 [startDate, setStartDate] = useState(''); const [endDate, setEndDate] = useState(''); const [minuteDifference, setMinuteDifference] = useState(null); const handleStartDateChange = (event) => { setStartDate(event.target.value); }; const handleEndDateChange = (event) => { setEndDate(event.target.value); }; const calculateMinuteDifference = () => { const startDateTime = new Date(startDate); const endDateTime = new Date(endDate); // Calculate the difference in milliseconds const differenceInMilliseconds = endDateTime - startDateTime; // Convert milliseconds to minutes const differenceInMinutes = differenceInMilliseconds / (1000 * 60); setMinuteDifference(differenceInMinutes); }; return ( <div className='container'> <h2>React Js Calculate Minute Difference Between Two Dates</h2> <div> <label>Start Date and Time:</label> <input type="datetime-local" value={startDate} onChange={handleStartDateChange} /> </div> <div> <label>End Date and Time:</label> <input type="datetime-local" value={endDate} onChange={handleEndDateChange} /> </div> <button onClick={calculateMinuteDifference}>Calculate</button> {minuteDifference !== null && ( <div> <p>Minute Difference: {minuteDifference} minutes</p> </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { border-radius: 8px; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; margin: 20px auto; max-width: 400px; text-align: center; } h2 { font-size: 24px; margin-bottom: 20px; } label { font-weight: bold; margin-bottom: 10px; display: block; } input[type="datetime-local"] { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 4px; } button { background-color: #007bff; color: #fff; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } div>p { font-size: 20px; margin-top: 20px; } </style> </body> </html>