Michael Kniskern Michael Kniskern - 5 months ago 14
Javascript Question

Get month in mm format in javascript

How do I retrieve the month from the current date in

mm
format? (i.e. "05")

This is my current code:

var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;

Answer
if (currentMonth < 10) { currentMonth = '0' + currentMonth; }