Get UTC time displayed in seconds in Jinja2 template

Hi, who know how i get the local datetime in jinja?
I tried below:

{{ now().strftime("%s") }}
{{ now().timestamp() | int }}

But i dont think its the exact same, i need a longer value as the explanation below…
who can help me?

thnx

A range of time is always interpreted as a closed-open interval, meaning that the start is inclusive, the end is exclusive. So requesting all 5min intervals for e.g. Oct 10 2020 (timezone Europe/Brussels) is done with the following range: [1602280800000, 1602367200000) where 1602280800000 is the UTC timestamp for Oct 10th 2020 and 1602367200000 is the UTC timestamp for Oct 11th 2020 (both timezone Europe/Brussels). The interval with timestamp 1602280800000 is already part of the next day so you do not want that. Using an open interval avoid that you always have to take one step back and subtract 5mins from 1602280800000. You can simply decide on the start of your interval and add the duration you are interested in and we will do the rest.

Seems i need a template to show the EPOCH time, it addes some zeros to the back

The examples you’ve posted are epoch times in milliseconds.

1 Like

aha, i just need to just multiply it, thnx!!

@troon

quick question

i need to substract a value first and then multiply it again, why doesnt this work ?

this is ok:

{{ now() | as_timestamp | int * 1000 }}

this doesnt work :

{{ now() | as_timestamp | (int - 86400 ) * 1000 }}

i get:

{{ (now() | as_timestamp - 86400) | int * 1000 }}
1 Like

omg, so easy :slight_smile: