Use new Date() to generate a new Date object containing the current date and time.

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;
document.write(today);

This will give you today's date in the format of mm/dd/yyyy.

Simply change today = mm +'/'+ dd +'/'+ yyyy; to whatever format you wish.

Answer from Samuel Meddows on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
In JavaScript, date objects are created with new Date(). new Date() returns a date object with the current date and time. ... The get methods above return Local time.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript - MDN Web Docs - Mozilla
Note: With the introduction of the Temporal API, the Date object is considered a legacy feature. Consider using Temporal for new code and migrate existing code over to it if possible (check the browser compatibility. We will be writing a usage guide soon! A JavaScript date is fundamentally specified as the time in milliseconds that has elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC (equivalent to the UNIX epoch).
🌐
W3Schools
w3schools.com › jsref › jsref_getdate.asp
JavaScript Date getDate() Method
The getDate() method returns the day of the month (1 to 31) of a date. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or ...
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - The most common way to create a ... no argument is passed​ · To get the current date, you can use the new Date() constructor without passing any arguments....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript - MDN Web Docs - Mozilla
// reduced time precision (2ms) in Firefox 60 new Date().getTime(); // Might be: // 1519211809934 // 1519211810362 // 1519211811670 // … // reduced time precision with `privacy.resistFingerprinting` enabled new Date().getTime(); // Might be: // 1519129853500 // 1519129858900 // 1519129864400 // … · The following examples show several ways to create JavaScript dates: js ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getDay
Date.prototype.getDay() - JavaScript - MDN Web Docs
The getDay() method of Date instances returns the day of the week for this date according to local time, where 0 represents Sunday. For the day of the month, see Date.prototype.getDate().
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › javascript-get-current-date-todays-date-in-js
JavaScript Get Current Date – Today's Date in JS
November 7, 2024 - But if you already have a library installed on your project or you're using it for other operations in your application, you can use it. In JavaScript, we can easily get the current date or time by using the new Date() object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript - MDN Web Docs - Mozilla
// reduced time precision (2ms) in Firefox 60 Date.now(); // Might be: // 1519211809934 // 1519211810362 // 1519211811670 // …
🌐
TutorialsPoint
tutorialspoint.com › javascript › date_getdate.htm
JavaScript Date getDate() Method
<html> <body> <script> const CurrentDate = new Date(); const DayOfMonth = CurrentDate.getDate(); document.write(DayOfMonth); </script> </body> </html>
🌐
Stack Abuse
stackabuse.com › how-to-get-the-current-date-in-javascript
How to Get the Current Date in JavaScript
October 11, 2023 - In JavaScript, there are a plethora of options to choose from, but the main class being used is Date(). It has a lot of methods and how you use it will depend on the format of the date you want to get.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to use javascript to get the current date and time
How to Use JavaScript to Get the Current Date and Time
December 17, 2025 - This guide explains how to get current date & time in JavaScript via multiple different methods, such as the Date object and moment.js.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-get-date-methods
JavaScript Get Date Methods - GeeksforGeeks
JavaScript Date Object allows us to get and set the date values.
Published   July 11, 2025
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getTime
Date.prototype.getTime() - JavaScript - MDN Web Docs
const moonLanding = new Date("July 20, 69 20:17:40 GMT+00:00"); // Milliseconds since Jan 1, 1970, 00:00:00.000 GMT console.log(moonLanding.getTime()); // Expected output: -14182940000
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-current-date-in-javascript
How to Get the Current Date in JavaScript ? - GeeksforGeeks
July 11, 2025 - You can extract individual components of date like —day, month, and year from the Date object. The getDate() method extract the date from Date object.
🌐
UltaHost
ultahost.com › knowledge-base › get-current-date-time-javascript
How to Use JavaScript to Get the Current Date and Time | Ultahost Knowledge Base
March 7, 2025 - Yes, use the getDay() method, which returns a number for the day (0 for Sunday, 1 for Monday, etc.). Tags : Display date time format date JavaScript Get time JavaScript JavaScript current date JavaScript current time JavaScript Date object ...
🌐
Reddit
reddit.com › r/learnjavascript › working with dates in javascript in an easy way
r/learnjavascript on Reddit: Working with Dates in JavaScript in an Easy Way
November 15, 2023 -

Source: https://www.webdevmonk.com/tutorials/js-tutorial-in-45minutes.html#14

You can create a new Date object by calling the Date constructor with no arguments, which will create a Date object set to the current date and time:

let currentDate = new Date();

Once you have a Date object, you can use its methods to get and set the date and time.

let currentDate = new Date();

console.log(currentDate.getFullYear()); // returns the year (e.g. 2022)

console.log(currentDate.getMonth()); // returns the month (0-11)

console.log(currentDate.getDate()); // returns the day of the month (1-31)

console.log(currentDate.getHours()); // returns the hour (0-23)

console.log(currentDate.getMinutes()); // returns the minute (0-59)

console.log(currentDate.getSeconds()); // returns the second (0-59)

currentDate.setFullYear(2021); // sets the year to 2021

currentDate.setMonth(11); // sets the month to December (11)

currentDate.setDate(25); // sets the day of the month to 25

currentDate.setHours(12); // sets the hour to 12 (noon)

currentDate.setMinutes(0); // sets the minute to 0

currentDate.setSeconds(0); // sets the second to 0

You can also create a Date object for a specific date and time by passing arguments to the Date constructor.

let birthday = new Date(1995, 0, 1); // January 1st, 1995

let meeting = new Date(2022, 11, 16, 13, 30, 0); // December 16th, 2022, 1:30 PM