get all dates in a mounth in typescript

You can use the Date object in TypeScript to get all the dates in a month. Here is an example code to get all the dates in the current month:

index.ts
const dates: Date[] = [];

// Get the current date
const today = new Date();

// Get the year and month of the current date
const year = today.getFullYear();
const month = today.getMonth();

// Loop through all the days in the month
for(let i = 1; i <= new Date(year, month + 1, 0).getDate(); i++) {
  // Create a new date object for each day
  const date = new Date(year, month, i);
  // Add the date object to the array
  dates.push(date);
}

console.log(dates);
465 chars
19 lines

The output of this code will be an array of Date objects, containing all the dates of the current month. You can change the today variable to any other date to get the dates of any other month.

gistlibby LogSnag