second() - Pine Script Function
second()
Section titled “second()”Overview
Section titled “Overview”second() extracts the second value (0–59) from a UNIX timestamp. By default the function uses the symbol’s exchange timezone (syminfo.timezone), but you can pass a custom UTC offset or IANA name to align with a different session or locale.
Syntax
Section titled “Syntax”second(time, timezone) → series intParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
time | series int | UNIX timestamp in milliseconds. Typically the built-in time series or a value returned by request.security(). |
timezone | series string (optional) | Target timezone, e.g., "UTC+02" or "America/New_York". Defaults to syminfo.timezone. |
Returns
Section titled “Returns”series int — Second component in the requested timezone.
Remarks
Section titled “Remarks”- The value reflects the timestamp at the open of each bar. For session-shifted assets it may differ from the visible trading second.
- Combine with
time(timeframe.period, session)to align calculations with custom sessions before extracting the second. - Useful for scripts that need sub-minute scheduling on intraday charts (e.g., highlight the :30 second of each minute).
Example
Section titled “Example”//@version=5indicator("Second-level highlight", overlay=true)
nySecond = second(time, "America/New_York")nyMinute = minute(time, "America/New_York")
isHalfMinute = nySecond == 30 and nyMinute % 5 == 0bgcolor(isHalfMinute ? color.new(color.purple, 85) : na, title="Highlight the 30th second every 5 minutes")