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>Date Format Example</title> </head> <body> <h1>Javascript Date Format dd-mm-yyyy hh mm ss</h1> <p id="currentdate"></p> <p id="output"></p> <button onclick="displayFormattedDate()">Show Formatted Date</button> <script> function formatDate(date) { const day = String(date.getDate()).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0'); const year = date.getFullYear(); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); return `${day}-${month}-${year} ${hours}:${minutes}:${seconds}`; } function displayFormattedDate() { const now = new Date(); const formattedDate = formatDate(now); document.getElementById('currentdate').textContent = `Current Date: ${now}`; // Display the formatted date on the webpage document.getElementById('output').textContent = `Formatted Date: ${formattedDate}`; } </script> </body> </html>