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 stringstr.format_time(input int time_value, input string format, input string timezone) → input stringstr.format_time(series int time_value, series string format, series string timezone) → series stringstr.format_time(simple int time_value, simple string format, simple string timezone) → simple string| Parameter | Type | Required | Description |
|---|---|---|---|
time_value | const int | yes | the time to render, as an int |
format | const string | yes | the format the result is written in |
timezone | const string | no | optional; 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.