mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Add a new filter: strftime. Use the well known function to format a date output. (#23832)
(cherry picked from commit 3f5b304fc28b6c34df9ea6a4c3531dc422ce198b) rebased for @yannig
This commit is contained in:
@@ -644,6 +644,24 @@ To always exhaust all list use ``zip_longest``::
|
||||
debug: msg="{{ [1,2,3]|zip_longest(['a','b','c','d','e','f'], [21, 22, 23], fillvalue='X')|list }}"
|
||||
|
||||
|
||||
.. versionadded:: 2.4
|
||||
To format a date using a string (like with the shell date command), use the "strftime" filter::
|
||||
|
||||
# Display year-month-day
|
||||
{{ '%Y-%m-%d' | strftime }}
|
||||
|
||||
# Display hour:min:sec
|
||||
{{ '%H:%M:%S' | strftime }}
|
||||
|
||||
# Use ansible_date_time.epoch fact
|
||||
{{ '%Y-%m-%d %H:%M:%S' | strftime(ansible_date_time.epoch) }}
|
||||
|
||||
# Use arbitrary epoch value
|
||||
{{ '%Y-%m-%d' | strftime(0) }} # => 1970-01-01
|
||||
{{ '%Y-%m-%d' | strftime(1441357287) }} # => 2015-09-04
|
||||
|
||||
.. note:: To get all string possibilities, check https://docs.python.org/2/library/time.html#time.strftime
|
||||
|
||||
Debugging Filters
|
||||
`````````````````
|
||||
|
||||
|
||||
Reference in New Issue
Block a user