Previous Page Next Page

Appendix C. Formatting Dates and Times

This appendix is a quick reference for when you format dates and times in your Django templates. The following tables list the format characters that are available for the now tag and the date and time filters. Table C.1 describes the available format characters for formatting dates. Table C.2 describes the available options for formatting times.

Table C.1. Date Format Characters Available for datetime Objects
CharacterDescriptionExample
bMonth, textual, three letters, lowercase.jan
dDay of the month, two digits with leading 0s.01 to 31
DDay of the week, textual, three letters.Mon to Sun
FMonth, textual, long.January
jDay of the month without leading 0s.1 to 31
lDay of the week, textual, long.Monday
LBoolean for whether it's a leap year.True or False
mMonth, two digits with leading 0s.01 to 12
MMonth, textual, three letters.Jan to Dec
nMonth, numeric, without leading 0s.1 to 12
NMonth in Associated Press style. Proprietary extension.Jan., Feb., March, May
rRFC 822 formatted date.Sat, 22 Sep 2007 18:12:05 +0700
SEnglish ordinal suffix for the day of the month, two characters.st, nd, rd, th
tNumber of days in the given month.28 to 31
wDay of the week, numeric without leading 0s.0 (Sunday) to 6 (Saturday)
WISO-8601 week number in the year, with weeks starting on Monday.1, 52
yYear, numeric, two digits.08
YYear, numeric, four digits.2008
zDay of the year, numeric.0 to 365


Table C.2. Time Format Characters Available for datetime and time Objects
CharacterDescriptionExample
aLowercase ante meridiem and post meridiem, with periods.a.m. or p.m.
AUppercase ante meridiem and post meridiem.AM or PM
fTime, in 12-hour hours and minutes, with minutes omitted if they're 00.1, 5:30
gHour, 12-hour format, without leading 0s.1 to 12
GHour, 24-hour format, without leading 0s.0 to 23
hHour, 12-hour format, with leading 0s.01 to 12
HHour, 24-hour format, with leading 0s.00 to 23
iMinutes, with leading 0s.00 to 59
ODifference to Greenwich time in hours, four digits.+0200
PTime, in 12-hour hours, with minutes and a.m./p.m., with minutes omitted if they're 00, and the special-case strings midnight and noon if appropriate.1 a.m., midnight, noon, 12:30 p.m., 5:30 p.m.
rRFC 822 formatted date.Sat, 22 Sep 200718:12:05 +0700
sSeconds, two digits with leading 0s.00 to 59
TTime zone of this machine.EST, MDT
ZTime zone offset in seconds. The offset for time zones west of UTC is always negative, and for those east of UTC, it is always positive.–43200 to 50400


Previous Page Next Page