summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-10-20 05:30:11 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-10-20 05:30:11 +0000
commit4c327b9c864f72be0d99f0b42c3d8e3134f27d4b (patch)
treeef83a012a123d64b992fffdcb7a395827a9b33f6 /docs
parent539e53ccf1b9da4acd095a4aeca4ab6ccc441543 (diff)
Lightly refactored django.utils.dateformat to make it use less code. Also integrated some of Sune's improvements from the #479 patch, including support for backslash escaping. Also vastly improved template docs for the {% now %} tag
git-svn-id: http://code.djangoproject.com/svn/django/trunk@969 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/templates.txt77
1 files changed, 71 insertions, 6 deletions
diff --git a/docs/templates.txt b/docs/templates.txt
index 5c52371c8a..9786b9fbf3 100644
--- a/docs/templates.txt
+++ b/docs/templates.txt
@@ -446,9 +446,9 @@ Built-in tag reference
<h1>Archive for {{ year }}</h1>
- {% for date in days %}
- {% ifchanged %}<h3>{{ date|date:"F" }}</h3>{% endifchanged %}
- <a href="{{ date|date:"M/d"|lower }}/">{{ date|date:"j" }}</a>
+ {% for day in days %}
+ {% ifchanged %}<h3>{{ day|date:"F" }}</h3>{% endifchanged %}
+ <a href="{{ day|date:"M/d"|lower }}/">{{ day|date:"j" }}</a>
{% endfor %}
``ifequal``
@@ -479,13 +479,78 @@ Built-in tag reference
``now``
Display the date, formatted according to the given string.
- Uses the same format as PHP's ``date()`` function; see http://php.net/date
- for all the possible values.
+ Uses the same format as PHP's ``date()`` function (http://php.net/date)
+ with some custom extensions.
- Sample usage::
+ Available format strings:
+
+ ================ ====================================== =====================
+ Format character Description Example output
+ ================ ====================================== =====================
+ a ``'a.m.'`` or ``'p.m.'`` (Note that ``'a.m.'``
+ this is slightly different than PHP's
+ output, because this includes periods
+ to match Associated Press style.)
+ A ``'AM'`` or ``'PM'``. ``'AM'``
+ B Not implemented.
+ d Day of the month, 2 digits with ``'01'`` to ``'31'``
+ leading zeros.
+ D Day of the week, textual, 3 letters. ``'Fri'``
+ f Time, in 12-hour hours and minutes, ``'1'``, ``'1:30'``
+ with minutes left off if they're zero.
+ Proprietary extension.
+ F Month, textual, long. ``'January'``
+ g Hour, 12-hour format without leading ``'1'`` to ``'12'``
+ zeros.
+ G Hour, 24-hour format without leading ``'0'`` to ``'23'``
+ zeros.
+ h Hour, 12-hour format. ``'01'`` to ``'12'``
+ H Hour, 24-hour format. ``'00'`` to ``'23'``
+ i Minutes. ``'00'`` to ``'59'``
+ I Not implemented.
+ j Day of the month without leading zeros. ``'1'`` to ``'31'``
+ l Day of the week, textual, long. ``'Friday'``
+ L Boolean for whether it's a leap year. ``True`` or ``False``
+ m Month, 2 digits with leading zeros. ``'01'`` to ``'12'``
+ M Month, textual, 3 letters. ``'Jan'``
+ n Month without leading zeros. ``'1'`` to ``'12'``
+ N Month abbreviation in Associated Press ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'``
+ style. Proprietary extension.
+ O Not implemented.
+ P Time, in 12-hour hours, minutes and ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'``
+ 'a.m.'/'p.m.', with minutes left off
+ if they're zero and the special-case
+ strings 'midnight' and 'noon' if
+ appropriate. Proprietary extension.
+ r Not implemented.
+ s Seconds, 2 digits with leading zeros. ``'00'`` to ``'59'``
+ S English ordinal suffix for day of the ``'st'``, ``'nd'``, ``'rd'`` or ``'th'``
+ month, 2 characters.
+ t Not implemented.
+ T Not implemented.
+ U Not implemented.
+ w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday)
+ leading zeros.
+ W ISO-8601 week number of year, with ``1``, ``23``
+ weeks starting on Monday.
+ y Year, 2 digits. ``'99'``
+ Y Year, 4 digits. ``'1999'``
+ z Day of the year. ``0`` to ``365``
+ Z Not implemented.
+
+ Example::
It is {% now "jS F Y H:i" %}
+ Note that you can backslash-escape a format string if you want to use the
+ "raw" value. In this example, "f" is backslash-escaped, because otherwise
+ "f" is a format string that displays the time. The "o" doesn't need to be
+ escaped, because it's not a format character.::
+
+ It is the {% "jS o\f F" %}
+
+ (Displays "It is the 4th of September" %}
+
``regroup``
Regroup a list of alike objects by a common attribute.