get the date for the last day of the current month in typescript

You can get the date for the last day of the current month in TypeScript by using the moment.js library. Here's an example:

index.ts
import * as moment from 'moment';

const lastDay = moment().endOf('month').format('YYYY-MM-DD');
console.log(lastDay); // outputs the date for the last day of the current month (e.g. "2021-02-28")
197 chars
5 lines

Here, we import the moment library and use the endOf('month') function to get the last day of the current month. We then format the result using the format function, with the 'YYYY-MM-DD' string parameter. This gives us the date string for the last day of the current month in the format YYYY-MM-DD.

gistlibby LogSnag