Hello,
I have a simple question that I’ve been struggling with for a long time.
My Wallbox provides the start and end times in UTC, e.g.
2025-10-03 11:08:54 – but it is actually 2025-10-03 13:08:54.
How can I add the current time difference to the UTC time?
Any help is appreciated !
Thanks, but is not I am looking for.
I got from my Wallbox a string for a start time: 2025-10-03 11:08:54. This is UTC/GMT time, but my local time is “2025-10-03 13:08:54” and that is the view I am looking for.
So I’m looking for a way to read my current time zone and add the time difference to UTC. In my case, it’s currently 2 hours, but during winter time it’s only one hour.
Can you clarify what the end goal is?
You can create a datetime object with a specific timezone from a timezone-naive datetime string by using strptime()…
{{ strptime('2025-10-03 11:08:54'~'+00:00','%Y-%m-%d %H:%M:%S%z') }}
… but I can’t tell if that’s really what you need because your end goal is unclear.
Why is my goal unclear ?
My Wallbox sends a string “2025-10-03 11:08:54” as a start-time - this time is UTC/GMT. I am based in Germany, so I have at the moment GMT+2.
I want to see the start-time in my timezone.
Means:
Wallbox sends: 2025-10-03 11:08:54
My local time is: 2025-10-03 13:08:54 and this format is the format I want to have. I do not want have “2025-10-03T11:08:54+02:00” or something similar.
Ok so you have string which looks like a datetime object without timezone information.
Paste the following into devtools>template
{% set utc_wo_tz = strptime('2025-10-03 11:08:54', '%Y-%m-%d %H:%M:%S') %}
{% set utc_wo_tz_timestamp = utc_wo_tz | as_timestamp %}
{% set timezone_offset = now().utcoffset().total_seconds()%}
{% set local_timestamp = utc_wo_tz_timestamp + timezone_offset %}
{% set local_wo_tz = local_timestamp | timestamp_custom('%Y-%m-%d %H:%M:%S', true) %}
{{utc_wo_tz}} the wallbox string
{{utc_wo_tz_timestamp}} turned into a timestamp
{{timezone_offset}} s calc the timzonedelta in seconds
{{local_timestamp}} calculated the local timestamp
{{ local_wo_tz }} turned this into readable form
I wouldn’t call that a propper solution, it’s more something to give you an idea about how to turn readable datetime informaiton into timestamps (number) one could do calculations with, and finally turn the result back into readable form.
You are my man ! You made my day !
Now, I have a clue what to do.
Many many thanks.
This solution was more or less born by a mixture of trail’n’error using limited braincells mixed with some ideas the cursor.com AI delivered. And both of use, me aswell as the AI are far from finding a real clever way.
I bet @Didgeridrew or some others with deeper knownledge hopfully share a much neater way in the end.
I have added a .%f to
{% set utc_wo_tz = strptime('2025-10-03 11:08:54.000', '%Y-%m-%d %H:%M:%S.%f') %}
because new FW is sending with miliseconds.
{% set source = '2025-10-03 11:08:54.000' %}
{% set source_utc_local = strptime(source~'+00:00', '%Y-%m-%d %H:%M:%S.%f%z')|as_local %}
{{ source_utc_local.strftime('%Y-%m-%d %H:%M:%S') }}
As I posted previously, if you know the source is UTC, use strptime() to create a timezone-aware datetime object. This allows you to use as_local to localize it to your current timezone with DST handled automatically. Since the result is still a datetime object, you can use the strftime() method to return a datetime string in your preferred format.