programming-examples/js/Date/Write a JavaScript function to get a numeric representation of a month, with leading zeros (01 through 12)..js

9 lines
232 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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));