Last_updated date format for the home assistant api

What is the format for last updated? I am using the HA REST api with Shortcuts and the date that I see is something like this

2020-10-28T16:05:46.510575+00:00

I’m guessing it is UTC time but i would have expected like +06:00 at the end. What am I missing? BTW I want to convert this time into CDT or local for me.

1 Like

UTC is +00:00

If it was in your timezone’s time it would be +0X:00.

OK so this leads me to believe that I have some configuration that is wrong. Shouldn’t i expect that via the API i get the last_updated key to show a +0X:00 ? Maybe i missed passing to my docker the timezone, could that be affecting this?

Nope, it’s UTC on purpose.

So what can i do to convert this to my local time? Do i just convert my time to UTC and subtract the two? I want to obtain (same as HA does it) where I have a “updated 12mins ago”

It’s easier than that. Just make a template sensor.

sensor:
- platform: template
  sensors:
    my_sensor_last_updated:
      device_class: timestamp
      value_template: "{{ states.sensor.xx.last_updated }}"

If you’re using custom_fields and writing the content, you can convert the sensor data into a javascript date and then do whatever with it:

custom_fields:
  progress: >
    [[[ return '<span style="position:absolute; text-align: center; left:160px;
    font-size:10px;">' + new Date(states['sensor.test_button_state'].last_updated).toLocaleString()  +
    '</span>']]]