How to Get the Current Date in JavaScript

A JavaScript Date is fundamentally specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC. By default, JavaScript will use the browser's time zone and display a date as a full text string.

Date objects in JavaScript

Date objects in JavaScript are created with the new Date() constructor. The new Date() creates a new date object with the current date and time. It has a lot of methods and how you use it will depend on the format of the date you want to get.

Simple JavaScript Date operation

var today = new Date(); document.getElementById("demo").innerHTML = "Today is: " + today;
run this source code Browser View

If you want to get Day, Month and Year separate then you can use the following code.
var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.getElementById("demo").innerHTML = "Today is: " + day + "/" + month + "/" + year;
run this source code Browser View


todays date inJavascript

Using Date.prototype.toLocaleDateString()

The toLocaleDateString() method returns a string with a language sensitive representation of the date portion of the specified date in the user agent's timezone.
today = new Date().toLocaleDateString() document.getElementById("demo").innerHTML = "Today is: " + today;
run this source code Browser View

Using Date.prototype.toISOString()

The toISOString() method returns a date object as a string, using the ISO standard. The standard is called ISO-8601 and the format is: YYYY-MM-DDTHH:mm:ss.sssZ.
today = new Date().toISOString().slice(0, 10) document.getElementById("demo").innerHTML = "Today is: " + today;
run this source code Browser View

Detailed date format

You can try this detailed date format like day name , month name etc.
run this source code Browser View

Full Source | JavaScript
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var objToday = new Date(), weekday = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), dayOfWeek = weekday[objToday.getDay()], domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + "").charAt(0)))) return "th"; a = parseInt((a + "").charAt(1)); return 1 == a ? "st" : 2 == a ? "nd" : 3 == a ? "rd" : "th" }(), dayOfMonth = today + ( objToday.getDate() < 10) ? '0' + objToday.getDate() + domEnder : objToday.getDate() + domEnder, months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), curMonth = months[objToday.getMonth()], curYear = objToday.getFullYear(); var today = dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear; document.getElementById("demo").innerHTML = "Today is: " + today; </script> </body> </html>
Finally, you can use a single line code using JSON for getting the current date.
today = new Date().toJSON().slice(0,10).replace(/-/g,'/'); document.getElementById("demo-6").innerHTML = "Today is: " + today;
run this source code Browser View

Moreover, you can use Date.js library which extends Date object , thus you can have .today() method.