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>Add Days to Date</title> </head> <body> <h1>Javascript Add Days to Date Example</h1> <!-- Display the result in specific elements with IDs --> <p id="currentDate"></p> <p id="futureDate3"></p> <p id="futureDate30"></p> <p id="futureDate7"></p> <script> // JavaScript code to add days to the current date function addDaysToCurrentDate(days) { let currentDate = new Date(); let futureDate = new Date(currentDate); futureDate.setDate(currentDate.getDate() + days); return futureDate.toDateString(); } // Example: Add 3 days to the current date let result3 = addDaysToCurrentDate(3); // Example: Add 30 days to the current date let result30 = addDaysToCurrentDate(30); // Example: Add 7 days to the current date let result7 = addDaysToCurrentDate(7); // Display the results in specific elements with IDs document.getElementById("currentDate").innerHTML = "Current Date: " + new Date().toDateString(); document.getElementById("futureDate3").innerHTML = "Future Date (after adding 3 days): " + result3; document.getElementById("futureDate30").innerHTML = "Future Date (after adding 30 days): " + result30; document.getElementById("futureDate7").innerHTML = "Future Date (after adding 7 days): " + result7; </script> </body> </html>