TimeGMTOffset
Syntax
TimeGMTOffset(): numberReturn Value
Description
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