Add documentation for as_datetime template method/filter (#18116)

This commit is contained in:
Franck Nijhof 2021-06-07 18:37:02 +02:00 committed by GitHub
parent c1f6e7ef5f
commit b9e2771b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,6 +134,8 @@ Other state examples:
{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.garage_door.last_changed) }}
{{ as_local(states.sensor.time.last_changed) }}
{{ states('sensor.expires') | as_datetime }}
```
{% endraw %}
@ -215,6 +217,7 @@ The same thing can also be expressed as a filter:
- `utcnow()` returns a datetime object of the current time in the UTC timezone.
- For specific values: `utcnow().second`, `utcnow().minute`, `utcnow().hour`, `utcnow().day`, `utcnow().month`, `utcnow().year`, `utcnow().weekday()` and `utcnow().isoweekday()`.
- Using `utcnow()` will cause templates to be refreshed at the start of every new minute.
- `as_datetime()` converts a string containing a timestamp to a datetime object.
- `as_timestamp()` converts datetime object or string to UNIX timestamp. This function also be used as a filter.
- `as_local()` converts datetime object to local time. This function also be used as a filter.
- `strptime(string, format)` parses a string based on a [format](https://docs.python.org/3.8/library/datetime.html#strftime-and-strptime-behavior) and returns a datetime object.