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> <script> function formatDateToYYYYMMDDHHMMSS(date) { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); 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 `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } function displayDates() { const currentDate = new Date(); const formattedDate = formatDateToYYYYMMDDHHMMSS(currentDate); document.getElementById('currentDate').innerText = `Current Date: ${currentDate.toLocaleString()}`; document.getElementById('formattedDate').innerText = `Formatted Date: ${formattedDate}`; } </script> </head> <body> <h2>Javascript Date Format yyyy-mm-dd hh mm ss</h2> <p id="currentDate"></p> <p id="formattedDate"></p> <button onclick="displayDates()">Click Me to Show Dates</button> </body> </html>