Second

Returns the current second.

Syntax

Second(): number

Return Value

Returns a number representing the current second (0-59).

Description

The Second method returns the second component of the current time. The returned value is between 0 and 59.

Example

// Get current second
const second = this.api.Second()
console.log(`Current second: ${second}`)

// Format second with leading zero
const formattedSecond = second.toString().padStart(2, '0')
console.log(`Formatted second: ${formattedSecond}`)

// Create full time string
const hour = this.api.Hour()
const minute = this.api.Minute()
const timeString = `${hour}:${minute}:${formattedSecond}`
console.log(`Current time: ${timeString}`)

// Check for minute boundary
const isStartOfMinute = second === 0
if (isStartOfMinute) {
    console.log('New minute started')
}

// Calculate seconds until next minute
const secondsUntilNextMinute = 60 - second
console.log(`Seconds until next minute: ${secondsUntilNextMinute}`)

// Check for time intervals
const isHalfSecond = second % 30 === 0
if (isHalfSecond) {
    console.log('Half-minute mark')
}

Last updated