#8913: add examples and docs for date/time/datetime.__format__. Patch by Heikki Partanen.
This commit is contained in:
parent
bf51717022
commit
cfb63cd3b1
|
@ -555,6 +555,13 @@ Instance methods:
|
||||||
section :ref:`strftime-strptime-behavior`.
|
section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: date.__format__(format)
|
||||||
|
|
||||||
|
Same as :meth:`.date.strftime`. This makes it possible to specify format
|
||||||
|
string for a :class:`.date` object when using :meth:`str.format`.
|
||||||
|
See section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
Example of counting days to an event::
|
Example of counting days to an event::
|
||||||
|
|
||||||
>>> import time
|
>>> import time
|
||||||
|
@ -605,6 +612,8 @@ Example of working with :class:`date`:
|
||||||
'11/03/02'
|
'11/03/02'
|
||||||
>>> d.strftime("%A %d. %B %Y")
|
>>> d.strftime("%A %d. %B %Y")
|
||||||
'Monday 11. March 2002'
|
'Monday 11. March 2002'
|
||||||
|
>>> 'The {1} is {0:%d}, the {2} is {0:%B}.'.format(d, "day", "month")
|
||||||
|
'The day is 11, the month is March.'
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-datetime:
|
.. _datetime-datetime:
|
||||||
|
@ -1044,6 +1053,13 @@ Instance methods:
|
||||||
string. See section :ref:`strftime-strptime-behavior`.
|
string. See section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: datetime.__format__(format)
|
||||||
|
|
||||||
|
Same as :meth:`.datetime.strftime`. This makes it possible to specify format
|
||||||
|
string for a :class:`.datetime` object when using :meth:`str.format`.
|
||||||
|
See section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
Examples of working with datetime objects:
|
Examples of working with datetime objects:
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
|
@ -1088,6 +1104,8 @@ Examples of working with datetime objects:
|
||||||
>>> # Formatting datetime
|
>>> # Formatting datetime
|
||||||
>>> dt.strftime("%A, %d. %B %Y %I:%M%p")
|
>>> dt.strftime("%A, %d. %B %Y %I:%M%p")
|
||||||
'Tuesday, 21. November 2006 04:30PM'
|
'Tuesday, 21. November 2006 04:30PM'
|
||||||
|
>>> 'The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.'.format(dt, "day", "month", "time")
|
||||||
|
'The day is 21, the month is November, the time is 04:30PM.'
|
||||||
|
|
||||||
Using datetime with tzinfo:
|
Using datetime with tzinfo:
|
||||||
|
|
||||||
|
@ -1268,6 +1286,13 @@ Instance methods:
|
||||||
See section :ref:`strftime-strptime-behavior`.
|
See section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: time.__format__(format)
|
||||||
|
|
||||||
|
Same as :meth:`.time.strftime`. This makes it possible to specify format string
|
||||||
|
for a :class:`.time` object when using :meth:`str.format`.
|
||||||
|
See section :ref:`strftime-strptime-behavior`.
|
||||||
|
|
||||||
|
|
||||||
.. method:: time.utcoffset()
|
.. method:: time.utcoffset()
|
||||||
|
|
||||||
If :attr:`tzinfo` is ``None``, returns ``None``, else returns
|
If :attr:`tzinfo` is ``None``, returns ``None``, else returns
|
||||||
|
@ -1314,6 +1339,8 @@ Example:
|
||||||
'Europe/Prague'
|
'Europe/Prague'
|
||||||
>>> t.strftime("%H:%M:%S %Z")
|
>>> t.strftime("%H:%M:%S %Z")
|
||||||
'12:10:30 Europe/Prague'
|
'12:10:30 Europe/Prague'
|
||||||
|
>>> 'The {} is {:%H:%M}.'.format("time", t)
|
||||||
|
'The time is 12:10.'
|
||||||
|
|
||||||
|
|
||||||
.. _datetime-tzinfo:
|
.. _datetime-tzinfo:
|
||||||
|
|
Loading…
Reference in New Issue