In this tutorial, We will learn how to momentjs get all dates in a month.
Lets learn by example:
<html>
<head>
<title>jquery moment example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>
</head>
<body>
<h1>jquery moment example get months</h1>
</body>
<script type="text/javascript">
var getDaysOfMonth = function (year, month) {
var monthDate = moment(year + '-' + month, 'YYYY-MM');
var daysInMonth = monthDate.daysInMonth();
var arrDays = [];
while (daysInMonth) {
var current = moment().date(daysInMonth);
arrDays.push(current.format('MM-DD-YYYY'));
daysInMonth--;
}
return arrDays;
};
////it wil return array of dates
var dateList = getDaysOfMonth(2021, 1);
console.log(dateList);
</script>
</html>
Now, You have understood what is movementjs to get all dates. Run your application enjoy the code.
Thanks, May this example will help you...