timestamptradingview-api

Hour and Minutes Timestamp in Pine Script


I tried to create candle's "hour and minutes" timestamp in Tradingview pine script. I could create hour timestamp but not minutes next to it. Can someone fix this problem?

//Time Stamp

inTime = (hour(time, syminfo.timezone))

Table_Def = table.new(position = position.middle_right, columns = 30, rows = 1, frame_color = color.black, frame_width = 1, border_color = color.black, border_width = 1)

table.cell(Table_Def, column = 0, row = 0, text = "Time", text_color = color.black, text_size = size.auto, text_halign = text.align_left)

table.cell(Table_Def, column = 1, row = 0, text = str.tostring(inTime[29]), text_color = color.black, text_size = size.auto, text_halign = text.align_right)


Solution

  • // Time Stamp

    inTime = str.format_time(time, "HH:mm", syminfo.timezone)

    Table_Def = table.new(position = position.middle_right, columns = 30, rows = 1, frame_color = color.black, frame_width = 1, border_color = color.black, border_width = 1)

    table.cell(Table_Def, column = 0, row = 0, text = "Time", text_color = color.black, text_size = size.auto, text_halign = text.align_left)

    table.cell(Table_Def, column = 29, row = 0, text = str.tostring(inTime[1]), text_color = color.black, text_size = size.auto, text_halign = text.align_right)

    table.cell(Table_Def, column = 30, row = 0, text = str.tostring(inTime[0]), text_color = color.black, text_size = size.auto, text_halign = text.align_right)

    and so on...

    I welcome any other format/syntax to fulfill the requirement as an alternative.