When we call getMonth() and getDate() on date object, we will get the single digit number.
For example :

For january, it displays 1, but I need to display it as 01. How to do that?

32 Answers
32

("0" + this.getDate()).slice(-2)

for the date, and similar:

("0" + (this.getMonth() + 1)).slice(-2)

for the month.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *