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> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [dateInfo, setDateInfo] = useState({ utcString: "", localString: "", hoursLocal: "", hoursUTC: "", }); useEffect(() => { let str = "2020-04-10T17:14:00"; let date = new Date(str + "Z"); setDateInfo({ utcString: date.toUTCString(), localString: date.toString(), hoursLocal: date.getHours(), hoursUTC: date.getUTCHours(), }); }, []); return ( <div className='container'> <h3>React Js Convert a String into a Date</h3> <p>UTC string: {dateInfo.utcString}</p> <p>Local string: {dateInfo.localString}</p> <p>Hours local: {dateInfo.hoursLocal}</p> <p>Hours UTC: {dateInfo.hoursUTC}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; margin: 50px auto; padding: 20px; width: 600px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); } input { width: 100%; padding: 10px; margin: 10px 0; border-radius: 5px; border: 1px solid #ccc; box-sizing: border-box; } button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s; margin-bottom:10px } button:hover { background-color: #0056b3; } </style> </body> </html>