Skip to content

second() - Pine Script Function

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.

second(time, timezone) → series int
NameTypeDescription
timeseries intUNIX timestamp in milliseconds. Typically the built-in time series or a value returned by request.security().
timezoneseries string (optional)Target timezone, e.g., "UTC+02" or "America/New_York". Defaults to syminfo.timezone.

series int — Second component in the requested timezone.

  • 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).
//@version=5
indicator("Second-level highlight", overlay=true)
nySecond = second(time, "America/New_York")
nyMinute = minute(time, "America/New_York")
isHalfMinute = nySecond == 30 and nyMinute % 5 == 0
bgcolor(isHalfMinute ? color.new(color.purple, 85) : na,
title="Highlight the 30th second every 5 minutes")