You can get the date for the first day of the current century in TypeScript/JavaScript using the Date
object and some simple arithmetic. Here's an example function to achieve this:
index.ts257 chars6 lines
The getFirstDayOfCentury
function first gets the current year using the getFullYear
method of the Date
object. Then, it calculates the start year of the current century using some simple arithmetic.
Finally, it returns a Date
object for the first day of the current century by creating a new Date
object for January 1st of the century start year.
gistlibby LogSnag