programming-examples/js/Date/Write a JavaScript function to get a numeric representation of a month, with leading zeros (01 through 12)..js
2019-11-15 12:59:38 +01:00

9 lines
232 B
JavaScript

function numeric_month(dt)
{
return (dt.getMonth() < 9 ? '0' : '') + (dt.getMonth() + 1);
}
dt = new Date();
console.log(numeric_month(dt));
dt = new Date(2015, 10, 1);
console.log(numeric_month(dt));