mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-22 16:56:50 +00:00
Time section: wording clarified, urls updated (#11979)
* Time section: wording clarified, urls updated There were some uncetrtanties/errors. Urls updated to point to the latest python docs * Update source/_docs/configuration/templating.markdown Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * wording changed * note rephrased/moved Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
d4f3baf39c
commit
b7be161bbe
@ -169,16 +169,20 @@ The same thing can also be expressed as a filter:
|
||||
|
||||
### Time
|
||||
|
||||
- `now()` will be rendered as the current time in your time zone.
|
||||
- For specific values: `now().second`, `now().minute`, `now().hour`, `now().day`, `now().month`, `now().year`, `now().weekday()` and `now().isoweekday()`
|
||||
- `utcnow()` will be rendered as UTC time.
|
||||
- `now()` returns a datetime object that represents the current time in your time zone.
|
||||
- You can also use: `now().second`, `now().minute`, `now().hour`, `now().day`, `now().month`, `now().year`, `now().weekday()` and `now().isoweekday()` and other [`datetime`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime) attributes and functions.
|
||||
- `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()`.
|
||||
- `as_timestamp()` will convert datetime object or string to UNIX timestamp. This function also be used as a filter.
|
||||
- `strptime(string, format)` will parse a string to a datetime based on a [format](https://docs.python.org/3.6/library/datetime.html#strftime-and-strptime-behavior).
|
||||
- `relative_time` will convert datetime object to its human-friendly "age" string. The age can be in second, minute, hour, day, month or year (but only the biggest unit is considered, e.g. if it's 2 days and 3 hours, "2 days" will be returned). Note that it only works for dates _in the past_.
|
||||
- Filter `timestamp_local` will convert an UNIX timestamp to local time/data.
|
||||
- Filter `timestamp_utc` will convert a UNIX timestamp to UTC time/data.
|
||||
- Filter `timestamp_custom(format_string, local_boolean)` will convert a UNIX timestamp to a custom format, the use of a local timestamp is default. Supports the standard [Python time formatting options](https://docs.python.org/3/library/time.html#time.strftime).
|
||||
- `as_timestamp()` converts datetime object or string to UNIX timestamp. 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.
|
||||
- `relative_time` converts datetime object to its human-friendly "age" string. The age can be in second, minute, hour, day, month or year (but only the biggest unit is considered, e.g. if it's 2 days and 3 hours, "2 days" will be returned). Note that it only works for dates _in the past_.
|
||||
- Filter `timestamp_local` converts an UNIX timestamp to its string representation as date/time in your local timezone.
|
||||
- Filter `timestamp_utc` converts a UNIX timestamp to its string representation representation as date/time in UTC timezone.
|
||||
- Filter `timestamp_custom(format_string, local_time=True)` converts an UNIX timestamp to its string representation based on a custom format, the use of a local timezone is default. Supports the standard [Python time formatting options](https://docs.python.org/3/library/time.html#time.strftime).
|
||||
Note: [UNIX timestamp](https://en.wikipedia.org/wiki/Unix_time) is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970. Therefore, if used as a function's argument, it can be substituted with a numeric value (`int` or `float`):
|
||||
```yaml
|
||||
{{ 120 | timestamp_local }}
|
||||
```
|
||||
|
||||
### To/From JSON
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user