Adding localized examples to strftime documentation.

This commit is contained in:
David Wolever 2013-04-13 20:50:24 -04:00
parent 73480ef578
commit c7953ef73e
1 changed files with 58 additions and 28 deletions

View File

@ -1616,11 +1616,19 @@ platforms. Regardless of platform, years before 1900 cannot be used.
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| Directive | Meaning | Example | Notes | | Directive | Meaning | Example | Notes |
+===========+================================+========================+=======+ +===========+================================+========================+=======+
| ``%a`` | Weekday as locale's | Sun, Mon, ..., Sat | | | ``%a`` | Weekday as locale's || Sun, Mon, ..., Sat | \(1) |
| | abbreviated name. | | | | | abbreviated name. | (en_US); | |
| | || So, Mo, ..., Sa | |
| | | (de_DE); | |
| | || 日, 月, ..., 土 | |
| | | (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%A`` | Weekday as locale's full name. | Sunday, Monday, ..., | | | ``%A`` | Weekday as locale's full name. || Sunday, Monday, ..., | \(1) |
| | | Saturday | | | | | Saturday (en_US); | |
| | || Sonntag, Montag, ..., | |
| | | Samstag (de_DE); | |
| | || 日曜日, 月曜日, ..., | |
| | | 土曜日 (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%w`` | Weekday as a decimal number, | 0, 1, ..., 6 | | | ``%w`` | Weekday as a decimal number, | 0, 1, ..., 6 | |
| | where 0 is Sunday and 6 is | | | | | where 0 is Sunday and 6 is | | |
@ -1629,14 +1637,18 @@ platforms. Regardless of platform, years before 1900 cannot be used.
| ``%d`` | Day of the month as a | 01, 02, ..., 31 | | | ``%d`` | Day of the month as a | 01, 02, ..., 31 | |
| | zero-padded decimal number. | | | | | zero-padded decimal number. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%j`` | Day of the year as a | 001, 002, ..., 366 | | | ``%b`` | Month as locale's abbreviated || Jan, Feb, ..., Dec | \(1) |
| | zero-padded decimal number. | | | | | name. | (en_US); | |
| | || Jan, Feb, ..., Dez | |
| | | (de_DE); | |
| | || 1, 2, ..., 12 (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%b`` | Month as locale's abbreviated | Jan, Feb, ..., Dec | | | ``%B`` | Month as locale's full name. || January, February, | \(1) |
| | name. | | | | | | ..., December (en_US);| |
+-----------+--------------------------------+------------------------+-------+ | | || Januar, Februar, ..., | |
| ``%B`` | Month as locale's full name. | January, February, | | | | | Dezember (de_DE); | |
| | | ..., December | | | | || 1月, 2月, ..., 12月 | |
| | | (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%m`` | Month as a zero-padded | 01, 02, ..., 12 | | | ``%m`` | Month as a zero-padded | 01, 02, ..., 12 | |
| | decimal number. | | | | | decimal number. | | |
@ -1653,27 +1665,31 @@ platforms. Regardless of platform, years before 1900 cannot be used.
| ``%I`` | Hour (12-hour clock) as a | 01, 02, ..., 12 | | | ``%I`` | Hour (12-hour clock) as a | 01, 02, ..., 12 | |
| | zero-padded decimal number. | | | | | zero-padded decimal number. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%p`` | Locale's equivalent of either | AM, PM | \(1) | | ``%p`` | Locale's equivalent of either || AM, PM (en_US); | \(1), |
| | AM or PM. | | | | | AM or PM. || am, pm (de_DE); | \(2) |
| | || AM, PM (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%M`` | Minute as a zero-padded | 00, 01, ..., 59 | | | ``%M`` | Minute as a zero-padded | 00, 01, ..., 59 | |
| | decimal number. | | | | | decimal number. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%S`` | Second as a zero-padded | 00, 01, ..., 61 | \(2) | | ``%S`` | Second as a zero-padded | 00, 01, ..., 61 | \(3) |
| | decimal number. | | | | | decimal number. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%f`` | Microsecond as a decimal | 000000, 000001, ..., | \(3) | | ``%f`` | Microsecond as a decimal | 000000, 000001, ..., | \(4) |
| | number, zero-padded on the | 999999 | | | | number, zero-padded on the | 999999 | |
| | left. | | | | | left. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%z`` | UTC offset in the form +HHMM | (empty), +0000, -0400, | \(4) | | ``%z`` | UTC offset in the form +HHMM | (empty), +0000, -0400, | \(5) |
| | or -HHMM (empty string if the | +1030 | | | | or -HHMM (empty string if the | +1030 | |
| | the object is naive). | | | | | the object is naive). | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%Z`` | Time zone name (empty string | (empty), UTC, EST, CST | | | ``%Z`` | Time zone name (empty string | (empty), UTC, EST, CST | |
| | if the object is naive). | | | | | if the object is naive). | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%U`` | Week number of the year | 00, 01, ..., 53 | \(5) | | ``%j`` | Day of the year as a | 001, 002, ..., 366 | |
| | zero-padded decimal number. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%U`` | Week number of the year | 00, 01, ..., 53 | \(6) |
| | (Sunday as the first day of | | | | | (Sunday as the first day of | | |
| | the week) as a zero padded | | | | | the week) as a zero padded | | |
| | decimal number. All days in a | | | | | decimal number. All days in a | | |
@ -1681,7 +1697,7 @@ platforms. Regardless of platform, years before 1900 cannot be used.
| | Sunday are considered to be in | | | | | Sunday are considered to be in | | |
| | week 0. | | | | | week 0. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%W`` | Week number of the year | 00, 01, ..., 53 | \(5) | | ``%W`` | Week number of the year | 00, 01, ..., 53 | \(6) |
| | (Monday as the first day of | | | | | (Monday as the first day of | | |
| | the week) as a decimal number. | | | | | the week) as a decimal number. | | |
| | All days in a new year | | | | | All days in a new year | | |
@ -1689,14 +1705,21 @@ platforms. Regardless of platform, years before 1900 cannot be used.
| | are considered to be in | | | | | are considered to be in | | |
| | week 0. | | | | | week 0. | | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%c`` | Locale's appropriate date and | Mon Aug 1 16:00:00 | | | ``%c`` | Locale's appropriate date and || Tue Aug 16 21:30:00 | \(1) |
| | time representation. | 1988 | | | | time representation. | 1988 (en_US), | |
| | || Di 16 Aug 21:30:00 | |
| | | 1988 (de_DE), | |
| | || 火 8/16 21:30:00 | |
| | | 1988 (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%x`` | Locale's appropriate date | 08/16/88 | | | ``%x`` | Locale's appropriate date || 08/16/88 (None), | \(1) |
| | representation. | | | | | representation. || 08/16/1988 (en_US), | |
| | || 16.08.1988 (de_DE), | |
| | || 1988/08/16 (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%X`` | Locale's appropriate time | 16:00:00 | | | ``%X`` | Locale's appropriate time || 21:30:00 (en_US), | \(1) |
| | representation. | | | | | representation. || 21:30:00 (de_DE), | |
| | || 21時30分00秒 (ja_JP) | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
| ``%%`` | A literal ``'%'`` character. | % | | | ``%%`` | A literal ``'%'`` character. | % | |
+-----------+--------------------------------+------------------------+-------+ +-----------+--------------------------------+------------------------+-------+
@ -1704,10 +1727,17 @@ platforms. Regardless of platform, years before 1900 cannot be used.
Notes: Notes:
(1) (1)
Because the format depends on the current locale, care should be taken when
making assumptions about the output value. Field orderings will vary (for
example, "month/day/year" versus "day/month/year"), and the output may
contain UTF-8 encoded unicode characters (for example, the ``ja_JP`` locale
may include Japanese characters).
(2)
When used with the :meth:`strptime` method, the ``%p`` directive only affects When used with the :meth:`strptime` method, the ``%p`` directive only affects
the output hour field if the ``%I`` directive is used to parse the hour. the output hour field if the ``%I`` directive is used to parse the hour.
(2) (3)
The range really is ``0`` to ``61``; according to the Posix standard this The range really is ``0`` to ``61``; according to the Posix standard this
accounts for leap seconds and the (very rare) double leap seconds. accounts for leap seconds and the (very rare) double leap seconds.
The :mod:`time` module may produce and does accept leap seconds since The :mod:`time` module may produce and does accept leap seconds since
@ -1715,7 +1745,7 @@ Notes:
does not accept leap seconds in :meth:`strptime` input nor will it does not accept leap seconds in :meth:`strptime` input nor will it
produce them in :func:`strftime` output. produce them in :func:`strftime` output.
(3) (4)
``%f`` is an extension to the set of format characters in the C standard ``%f`` is an extension to the set of format characters in the C standard
(but implemented separately in datetime objects, and therefore always (but implemented separately in datetime objects, and therefore always
available). When used with the :meth:`strptime` method, the ``%f`` available). When used with the :meth:`strptime` method, the ``%f``
@ -1723,7 +1753,7 @@ Notes:
.. versionadded:: 2.6 .. versionadded:: 2.6
(4) (5)
For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty
strings. strings.
@ -1742,7 +1772,7 @@ Notes:
string. Otherwise ``%Z`` is replaced by the returned value, which must string. Otherwise ``%Z`` is replaced by the returned value, which must
be a string. be a string.
(5) (6)
When used with the :meth:`strptime` method, ``%U`` and ``%W`` are only used When used with the :meth:`strptime` method, ``%U`` and ``%W`` are only used
in calculations when the day of the week and the year are specified. in calculations when the day of the week and the year are specified.