str.format_time

Renders a time value as text. The format is a specimen date rather than a set of escapes: write out 2006-01-02 15:04:05 in the arrangement you want. The optional timezone defaults to UTC. Note the unit. This function reads its first argument as seconds, while time, time_close, timenow and timestamp all produce milliseconds, so divide by a thousand first. Passing a time value straight in reports a wrong date and raises nothing.

str.format_time(const int time_value, const string format, const string timezone) → const string
str.format_time(input int time_value, input string format, input string timezone) → input string
str.format_time(series int time_value, series string format, series string timezone) → series string
str.format_time(simple int time_value, simple string format, simple string timezone) → simple string
ParameterTypeRequiredDescription
time_valueconst intyesthe time to render, as an int
formatconst stringyesthe format the result is written in
timezoneconst stringnooptional; the timezone the result is expressed in

Returns const string or input string or series string or simple string — The formatted text, or na where the timezone is not recognised.

indicator("The bar's date as text")
alert(str.format_time(math.floor(time / 1000), "2006-01-02", "UTC"))
plot(close)

See also str.contains · str.endswith · str.length

Part of the function index.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade