Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to get the current date using JavaScript?

1 Answer

0 votes
by (26.7k points)

In able to get the current date, you need to create a Date object, below is the code you can prefer as a reference:

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);

You can also able to change the date format, according to you.

I hope this will help.

Want to become a Java expert? join Java Training now!!

Related questions

0 votes
1 answer
–1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 28, 2021 in Java by dante07 (13.1k points)

Browse Categories

...