Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Get the Current Date</title> </head> <body> <script> // Create a date object var today = new Date(); // Generate current date string in UK date format (day-month-year) var ukDate = today.toLocaleDateString("en-GB", { year: "numeric", month: "2-digit", day: "2-digit", }); document.write(ukDate + "<br>"); // Generate current date string in US date format (month-day-year) var usDate = today.toLocaleDateString("en-US", { year: "numeric", month: "2-digit", day: "2-digit", }); document.write(usDate); </script> </body> </html>