Format a date in Javascript.

24 days ago23k times

code to format a date in JavaScript.


let objectDate = new Date();



let day = objectDate.getDate();
console.log(day); // 12


let currentmo = objectDate.getMonth();
month = currentmo + 1;
console.log(month + 1); // 1


let year = objectDate.getFullYear();
console.log(year); // 2023



// Now you can set it accordingly


// dd/mm/yyyy
console.log(day + '/' + month + '/' + year);


// mm/dd/yyyy
console.log(month + '/' + day + '/' + year);

Add Answer

Add a codeAdd Code
Remove adsremove

Latest codes

view all

Latest Snippets

view all