TimeGMTOffset

Returns the difference between GMT and local time.

Syntax

TimeGMTOffset(): number

Return Value

Returns a number representing the difference in seconds between GMT and local time.

Description

The TimeGMTOffset method calculates and returns the offset between GMT (UTC) and local time in seconds. This offset represents the timezone difference and includes any daylight savings time adjustments. A positive value means the local time is ahead of GMT, while a negative value means it's behind.

Example

// Get GMT offset
const offset = this.api.TimeGMTOffset()
console.log(`GMT offset: ${offset} seconds`)

// Convert to hours
const offsetHours = offset / 3600
console.log(`GMT offset in hours: ${offsetHours}`)

// Check if ahead or behind GMT
if (offset > 0) {
    console.log(`Local time is ${offsetHours} hours ahead of GMT`)
} else if (offset < 0) {
    console.log(`Local time is ${Math.abs(offsetHours)} hours behind GMT`)
} else {
    console.log('Local time is same as GMT')
}

// Use offset for time conversions
const localTime = this.api.TimeLocal()
const gmtTime = localTime - offset
console.log(`Converted local to GMT: ${new Date(gmtTime * 1000).toUTCString()}`)

Last updated