get the date for the first day of the current year in typescript

To get the date for the first day of the current year in TypeScript, you can use the built-in Date object and its methods.

Here's an example code that will return the date for the first day of the current year:

index.ts
const currentYear = new Date().getFullYear();

const firstDayOfYear = new Date(currentYear, 0, 1);

console.log(firstDayOfYear);
129 chars
6 lines

The getFullYear() method is used to get the current year, and then a new Date object is created with new Date(currentYear, 0, 1). The second argument (0) represents January, and the third argument (1) represents the first day of the month.

This code will output something like this: Tue Jan 01 2022 00:00:00 GMT+0100 (Central European Standard Time) for the current year 2022.

gistlibby LogSnag