dateformat¶
Similar to the date
filter, but instead of using format strings derived from PHP, use the normal format strings for Python’s strftime
.
Note
Make sure to install dj_angles
and include {% load dj_angles %}
in your template if "dj_angles.templatetags.dj_angles"
is not added to template built-ins.
<!-- index.html -->
{{ book.published_at|dateformat:"%Y-%m-%d" }} <!-- 2023-03-15 -->
Format strings¶
Day¶
|
|
Description |
Example |
---|---|---|---|
%d |
d |
Day of the month, 2 digits with leading zeros. |
|
%-d |
j |
Day of the month without leading zeros. |
|
%a |
D |
Day of the week, textual, 3 letters. |
|
%A |
l |
Day of the week, textual, long. |
|
– |
S |
English ordinal suffix for day of the month, 2 characters. |
|
%w |
w |
Day of the week, digits without leading zeros. |
|
%-j |
z |
Day of the year. |
|
Week¶
|
|
Description |
Example |
---|---|---|---|
%-W |
W |
ISO-8601 week number of year, with weeks starting on Monday. |
|
Month¶
|
|
Description |
Example |
---|---|---|---|
%m |
m |
Month, 2 digits with leading zeros. |
|
%-m |
n |
Month without leading zeros. |
|
%b |
M |
Month, textual, 3 letters. |
|
– |
b |
Month, textual, 3 letters, lowercase. |
|
– |
E |
Month, locale specific alternative representation. |
|
%B |
F |
Month, textual, long. |
|
– |
N |
Month abbreviation in Associated Press style. |
|
– |
t |
Number of days in the given month. |
|
Year¶
|
|
Description |
Example |
---|---|---|---|
%y |
y |
Year, 2 digits with leading zeros. |
|
%Y |
Y |
Year, 4 digits with leading zeros. |
|
– |
L |
Boolean for whether it’s a leap year. |
|
– |
o |
ISO-8601 week-numbering year. |
|
Time¶
|
|
Description |
Example |
---|---|---|---|
%-I |
g |
Hour, 12-hour format without leading zeros. |
|
%-H |
G |
Hour, 24-hour format without leading zeros. |
|
%I |
h |
Hour, 12-hour format. |
|
%H |
H |
Hour, 24-hour format. |
|
%M |
i |
Minutes. |
|
%S |
s |
Seconds, 2 digits with leading zeros. |
|
%f |
u |
Microseconds. |
|
– |
a |
|
|
%p |
A |
|
|
– |
f |
Time, in 12-hour hours and minutes, with minutes left off if they’re zero. |
|
– |
P |
Time, in 12-hour hours, minutes and ‘a.m.’/’p.m.’, with minutes left off if they’re zero and the special-case strings ‘midnight’ and ‘noon’ if appropriate. |
|
Timezone¶
|
|
Description |
Example |
---|---|---|---|
%Z |
e |
Timezone name. Could be in any format, or might return an empty string, depending on the datetime. |
|
– |
I |
Daylight saving time, whether it’s in effect or not. |
|
%z |
O |
Difference to Greenwich time in hours. |
|
– |
T |
Time zone of this machine. |
|
– |
Z |
Time zone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. |
|
Date/Time¶
|
|
Description |
Example |
---|---|---|---|
– |
c |
ISO 8601 format. (Note: unlike other formatters, such as “Z”, “O” or “r”, the “c” formatter will not add timezone offset if value is a naive datetime.) |
|
– |
r |
RFC 5322 formatted date. |
|
– |
U |
Seconds since the Unix Epoch (January 1 1970 00:00:00 UTC). |