screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Timestamp to Date Converter</title> </head> <body> <h1>Javascript timestamp to date yyyy-mm-dd hh-mm-ss</h1> <p>Click the button to display the current timestamp and corresponding date:</p> <button onclick="convertTimestamp()">Show Timestamp</button> <p id="timestampOutput"></p> <p id="formattedDateOutput"></p> <script> function convertTimestamp() { const currentTimestamp = Date.now(); const formattedDate = timestampToDateString(currentTimestamp); document.getElementById('timestampOutput').innerHTML = `Current Timestamp: ${currentTimestamp}`; document.getElementById('formattedDateOutput').innerHTML = `Formatted Date: ${formattedDate}`; } function timestampToDateString(timestamp) { const date = new Date(timestamp); const yyyy = date.getFullYear(); const mm = String(date.getMonth() + 1).padStart(2, '0'); const dd = String(date.getDate()).padStart(2, '0'); const hh = String(date.getHours()).padStart(2, '0'); const min = String(date.getMinutes()).padStart(2, '0'); const ss = String(date.getSeconds()).padStart(2, '0'); return `${yyyy}-${mm}-${dd} ${hh}-${min}-${ss}`; } </script> </body> </html>