TimeHour

Returns the hour from a Unix timestamp.

Syntax

TimeHour(unixTimeSeconds: number): number

Parameters

  • unixTimeSeconds: number - Unix timestamp in seconds since epoch

Return Value

Returns a number representing the hour (0-23).

Description

The TimeHour method extracts the hour from a given Unix timestamp. The returned value is between 0 and 23, representing the hour in 24-hour format.

Example

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

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

// Check for trading hours (9:30 - 16:00)
const isWithinTradingHours = hour >= 9 && hour < 16;
console.log(`Within trading hours: ${isWithinTradingHours}`);

// Format in AM/PM
const period = hour >= 12 ? "PM" : "AM";
const hour12 = hour % 12 || 12;
console.log(`Time: ${hour12}${period}`);

Last updated