Django filter date formatting

Source: Internet
Author: User
Now

Displays the current date. The output format is determined based on the specified string.

Use the same format code (http://php.net/date) as the date () function of PHP and make some extensions

 

Date

Format a date based on the given format (the same as the now label.

 

Available Format String:

 

 

Format characters Description Output example
A 'A. M. 'or 'p. M.' (note that it is slightly different from the PHP output. It includes a period (Django extension ). 'A. M .'
A 'Am' or 'pm '. 'Am'
B Not implemented.  
D The day of each month, with a leading zero '01 'to '31'
D The day of the week, a string of 3 letters. 'Fri'
F Time, in 12-hour format, the hour and the number of minutes. If the number of minutes is zero, it is not displayed. (Django extension ). '1', '1: 30'
F Month, in long text format. 'January'
G Hour, in 12-hour format, without leading zero '1' to '12'
G Hour, in 24-hour format, with no leading zero '0' to '23'
H Hour, in 12-hour format, with a leading zero '01 'to '12'
H Hour, in 24-hour format, with a leading zero '00' to '23'
I Minutes. '00' to '59'
I Not Implemented  
J The day of each month, with no leading zero '1' to '31'
L The day of the week in long text format. 'Friday'
L Whether it is a leap year. True or false
M Number indicates the month, with a leading zero. '01 'to '12'
M Month, 3-letter short text format. 'Jan'
N Number indicates the month without leading zero '1' to '12'
N Abbreviation of published month (Django extension) 'Jan. ', 'feb.', 'march', 'may'
O Time Difference from Greenwich Mean (hours) '+ 123'
P 12-hour minutes and 'a. m. '/' p. m. 'If the number of minutes is zero, it is not displayed. represents special time points with strings, such as 'midnight 'and 'noon' (Django extension) '1 a. m. ', '1: 30 p. m.', 'midnight ', 'noon', '12: 30 p. m .'
R Date in RFC 822 format. 'Thu, 21 Dec 2000 16:01:07 + 123'
S Number of seconds, with a leading zero number '00' to '59'
S Suffix of the English ordinal number, used for the day of a month, 2 Characters 'St', 'nd', 'RD 'or 'th'
T The total number of days in a given month. 28 to 31
T Local time zone. 'Est ', 'mdt'
U Not Implemented  
W The day of the week without a leading zero number '0' (Sunday) to '6' (Saturday)
W The number of weeks in a year in ISO-8601, starting from Monday. 1, 23
Y Year, two digits '99'
Y Year, 4-digit representation '123'
Z The day of the year. 0 to 365
Z The offset of the time zone in seconds. This offset is always negative for the Western UTC time zone, while it is always positive for the Eastern UTC time zone. -From 43200 to 43200

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.