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 [date1, setDate1] = useState(''); const [date2, setDate2] = useState(''); const [result, setResult] = useState(''); const handleDateChange = (event, setter) => { setter(event.target.value); } const compareDates = () => { const timestamp1 = Date.parse(date1); const timestamp2 = Date.parse(date2); if (isNaN(timestamp1) || isNaN(timestamp2)) { setResult('Invalid date format'); } else if (timestamp1 === timestamp2) { setResult('Dates are equal'); } else if (timestamp1 < timestamp2) { setResult('Date 1 is earlier than Date 2'); } else { setResult('Date 1 is later than Date 2'); } } return ( <div className="container"> <h3>React Js Compare Two Dates</h3> <label>Date 1:</label> <input type="date" value={date1} onChange={(e) => handleDateChange(e, setDate1)} /> <label>Date 2:</label> <input type="date" value={date2} onChange={(e) => handleDateChange(e, setDate2)} /> <button onClick={compareDates}>Compare Dates</button> <p>{result}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .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; } h3 { font-size: 24px; margin-bottom: 20px; } label { display: block; font-weight: bold; margin-bottom: 10px; } input[type="date"] { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 5px; } button { padding: 10px 20px; background-color: #4caf50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #45a049; } p { margin-top: 20px; font-weight: bold; } </style> </body> </html>