TimeToStruct
Syntax
TimeToStruct(unixTimeSeconds: number): FTODateParameters
Return Value
Description
Example
// Convert timestamp to FTODate
const timestamp = 1707739200; // 2024.02.12 12:00:00 UTC
const date = this.api.TimeToStruct(timestamp);
console.log(`Converted date: ${date.toString()}`);
// Access date components
console.log(`Year: ${date.yearOf()}`);
console.log(`Month: ${date.monthOf()}`);
console.log(`Day: ${date.dayOfMonth()}`);
console.log(`Hour: ${date.hour()}`);
console.log(`Minute: ${date.minute()}`);
console.log(`Second: ${date.second()}`);
// Convert multiple timestamps
const timestamps = [1707739200, 1707825600, 1707912000]; // Three consecutive days
for (let i = 0; i < timestamps.length; i++) {
const date = this.api.TimeToStruct(timestamps[i]);
console.log(`Date ${i + 1}: ${date.toString()}`);
}
// Compare dates
const date1 = this.api.TimeToStruct(1707739200);
const date2 = this.api.TimeToStruct(1707825600);
const diffInDays = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);
console.log(`Days between dates: ${diffInDays}`);Last updated