TimeMonth

Returns the month from a Unix timestamp.

Syntax

TimeMonth(unixTimeSeconds: number): number

Parameters

  • unixTimeSeconds: number - Unix timestamp in seconds since epoch

Return Value

Returns a number representing the month (1-12).

Description

The TimeMonth method extracts the month from a given Unix timestamp. The returned value is between 1 and 12, where 1 represents January and 12 represents December.

Example

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

// Format with leading zero
const formattedMonth = month.toString().padStart(2, "0");
console.log(`Formatted month: ${formattedMonth}`);

// Get month name
const monthNames = [
  "January",
  "February",
  "March",
  "April",
  "May",
  "June",
  "July",
  "August",
  "September",
  "October",
  "November",
  "December",
];
console.log(`Month name: ${monthNames[month - 1]}`);

// Check for quarter end
const isQuarterEnd = month % 3 === 0;
console.log(`Is quarter end: ${isQuarterEnd}`);

Last updated