Formats a UNIX timestamp in milliseconds as text, using a pattern and an optional time zone.
str.format_time turns a time value such as time or timenow into readable text. The default pattern is "yyyy-MM-dd'T'HH:mm:ssZ".
Patterns use letters: yyyy for the year, MM for the month, dd for the day, HH for hours on a 24-hour clock, mm for minutes and ss for seconds. Text in single quotes stays literal.
Syntax
str.format_time(time: series int, format: series string (optional), timezone: series string (optional)) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| time | series int | required | UNIX time in milliseconds. |
| format | series string | "yyyy-MM-dd'T'HH:mm:ssZ" | The date and time pattern. |
| timezone | series string | the chart's time zone | Time zone name such as "America/New_York", or an offset like "UTC+2". |
Returns
series string: the formatted date and time; na if time is na.
Remarks
- Without a timezone the exchange time zone of the chart is used.
- An unknown time zone name stops the script with an error.
Example
//@version=6
indicator("Format time")
hourText = str.format_time(time, "HH", "America/New_York")
plot(str.tonumber(hourText), "NY hour", color = color.blue, style = plot.style_stepline)See also
Runs on Sidechair