TimeYear

Returns the year from a Unix timestamp.

Syntax

TimeYear(unixTimeSeconds: number): number

Parameters

  • unixTimeSeconds: number - Unix timestamp in seconds since epoch

Return Value

Returns a number representing the year.

Description

The TimeYear method extracts the year from a given Unix timestamp. The returned value is a four-digit year number (e.g., 2024).

Example

// Get year from timestamp
const timestamp = 1707739200; // 2024.02.12 12:00:00 UTC
const year = this.api.TimeYear(timestamp);
console.log(`Year: ${year}`);

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

// Calculate years between timestamps
const timestamp2 = 1676203200; // 2023.02.12 12:00:00 UTC
const year2 = this.api.TimeYear(timestamp2);
const yearsDiff = year - year2;
console.log(`Years difference: ${yearsDiff}`);

// Format full date
const month = this.api.TimeMonth(timestamp);
const day = this.api.TimeDay(timestamp);
console.log(`Date: ${year}.${month}.${day}`);

Last updated