screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [inputDate, setInputDate] = useState(''); const [unixTimestamp, setUnixTimestamp] = useState(null); const convertToTimestamp = () => { const inputDateObj = new Date(inputDate); if (!isNaN(inputDateObj)) { const unixTimestamp = inputDateObj.getTime() / 1000; setUnixTimestamp(unixTimestamp); } else { setUnixTimestamp(null); } }; return ( <div className='container'> <h3>React Js Convert Date to Unix Timestamp </h3> <input type="date" value={inputDate} onChange={(e) => setInputDate(e.target.value)} className="date-input" /> <button onClick={convertToTimestamp} className="timestamp-button"> Convert to Unix Timestamp </button> <div className="timestamp-result"> {unixTimestamp !== null ? ( <p>Unix Timestamp: {unixTimestamp}</p> ) : ( <p>Invalid Date</p> )} </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } /* Style the input field */ .date-input { padding: 10px; margin: 10px; border: 2px solid #ccc; border-radius: 5px; font-size: 16px; width: 80%; } /* Style the timestamp button */ .timestamp-button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s; } .timestamp-button:hover { background-color: #0056b3; } /* Style the timestamp result container */ .timestamp-result { margin: 20px 0; } /* Style the timestamp result text */ .timestamp-result p { font-size: 18px; font-weight: bold; } /* Style the "Invalid Date" message */ .timestamp-result p:last-child { color: #ff0000; font-weight: normal; } /* Style the "Unix Timestamp" text */ .timestamp-result p:first-child { color: #4caf50; } </style> </body> </html>