Year

Returns the current year.

Syntax

Year(): number

Return Value

Returns a number representing the current year.

Description

The Year method returns the year component of the current time. The returned value is a four-digit year number (e.g., 2024).

Example

// Get current year
const year = this.api.Year();
console.log(`Current year: ${year}`);

// Check for leap year
const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
console.log(`Is leap year: ${isLeapYear}`);

// Calculate years since a specific date
const startYear = 2000;
const yearsSince = year - startYear;
console.log(`Years since ${startYear}: ${yearsSince}`);

// Format as two digits
const twoDigitYear = year.toString().slice(-2);
console.log(`Two-digit year: ${twoDigitYear}`);

// Calculate decade
const decade = Math.floor(year / 10) * 10;
console.log(`Current decade: ${decade}s`);

Last updated