Button card addon and as_timestamp problem

Good morning.
I’ve a problem with button card and as_time stamp:

In The administrative tools → models

{{as_timestamp(states['sensor.record_temperatura_massima'].attributes.quando) | timestamp_custom('%d/%m/%Y alle ore: %H:%M')}}

working fine.

this is an excerpt of the code of an advanced button card

[...]
  info2: |
    [[[
      return `<ha-icon
        icon="mdi:calendar"
        style="width: 12px; height: 12px; color: white;">
        </ha-icon><span> registrata il: <span style="color: var(--text-color-sensor);">${states['sensor.record_temperatura_massima'].attributes.quando}%</span></span>`
    ]]]

[...]

works but in agreement with the “quando” attribute, the output is a unformatted timestamp

Why this not working (the button disappear)

[...]
  info2: |
    [[[
      return `<ha-icon
        icon="mdi:calendar"
        style="width: 12px; height: 12px; color: white;">
        </ha-icon><span> registrata il: <span style="color: var(--text-color-sensor);">${as_timestamp(states['sensor.record_temperatura_massima'].attributes.quando) | timestamp_custom('%d/%m/%Y alle ore: %H:%M')}%</span></span>`
    ]]]

[...]

Thanks

Button card templates use JS, not jinja, so jinja will not work. Timestamp_custom is jinja

OK.
Thanks.
There’s a way to solve?

Yes, you’d have to solve it using JS. I don’t have the code memorized, and I’d have to Google it when I’m at a computer. But you need to change the time int into a Date then format it.

Thanks Petro.
This working but… is the right way?

  info2: |
    [[[
      var data_temp_max = new Date(states['sensor.record_temperatura_massima'].attributes.quando);
      return `<ha-icon
        icon="mdi:calendar"
        style="width: 20px; height: 20px; color: white;">
        </ha-icon><span> registrata il: <span style="color: var(--text-color-sensor);">${data_temp_max.toLocaleDateString()} alle ore ${data_temp_max.toLocaleTimeString()}</span></span>`
    ]]]

If you like the format, then the code is fine. There’s no way to optimize it if that’s what you’re asking.