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 [time1, setTime1] = useState('10:30:45'); const [time2, setTime2] = useState('12:15:30'); const [result, setResult] = useState(null); const compareTimes = () => { if (time1 < time2) { setResult(`${time1} is earlier than ${time2}`); } else if (time1 > time2) { setResult(`${time1} is later than ${time2}`); } else { setResult(`${time1} is equal to ${time2}`); } }; return ( <div className='container'> <h3 className='title'>React Js Compare Time String 24 Hours Format</h3> <input type="text" className='input' value={time1} onChange={(e) => setTime1(e.target.value)} /> <input type="text" className='input' value={time2} onChange={(e) => setTime2(e.target.value)} /> <button className='button' onClick={compareTimes}>Compare Times</button> <p className='result'>{result}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { 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); width: 600px; margin: 0 auto; padding: 20px; } .title { font-size: 24px; margin: 0 0 20px; color: #333; } .input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; } .button { background-color: #007bff; color: #fff; border: none; border-radius: 5px; padding: 10px 20px; cursor: pointer; font-size: 16px; transition: background-color 0.3s; } .button:hover { background-color: #0056b3; } .result { font-size: 18px; margin: 10px 0; } </style> </body> </html>