Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

How do I get the current date in JavaScript?

1 Answer

0 votes
by (106k points)
edited by

To get the current date in JavaScript you can use new Date()method 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');

var yyyy = today.getFullYear(); 

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

image

Related questions

0 votes
1 answer
asked Aug 13, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...