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

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

if(dd < 10) {
    dd = '0'+dd
} 

if(mm < 10) {
    mm = '0'+mm
} 

today = dd+ '/' + mm + '/' + yyyy;
console.log(today);

This will give you today’s date in the format of dd/mm/yyyy. Simply change today = dd+'/'+ mm+'/'+ yyyy; to whatever format you wish.

Last modified: January 12, 2018

Author