screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <title>Random Date Generator</title> </head> <body> <h2>Javascript generate random date betweeen two dates</h2> <button onclick="generateRandomDate()">Generate Random Date</button> <p id="result"></p> <script> function getRandomDate(start, end) { var startDate = start.getTime(); var endDate = end.getTime(); var randomTimestamp = Math.random() * (endDate - startDate) + startDate; var randomDate = new Date(randomTimestamp); return randomDate; } function generateRandomDate() { var startDate = new Date("2023-01-01"); var endDate = new Date("2023-12-31"); var randomDate = getRandomDate(startDate, endDate); var resultContainer = document.getElementById("result"); resultContainer.innerHTML = randomDate.toDateString(); } </script> </body> </html>