Month

Returns the current month.

Syntax

Month(): number

Return Value

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

Description

The Month method returns the month component of the current time. The returned value is between 1 and 12, where 1 represents January and 12 represents December.

Example

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

// Format month 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 specific months
if (month === 1) {
  console.log("First month of the year");
} else if (month === 12) {
  console.log("Last month of the year");
}

// Check for quarter end
if (month % 3 === 0) {
  console.log("End of quarter");
}

Last updated