diff -r d089b8fb0f56 Doc/library/datetime.rst --- a/Doc/library/datetime.rst Mon Oct 22 15:13:01 2012 -0700 +++ b/Doc/library/datetime.rst Tue Oct 30 07:32:26 2012 +0200 @@ -555,6 +555,13 @@ section :ref:`strftime-strptime-behavior`. +.. method:: date.__format__(format) + + Same as ``date.strftime``. This makes it possible to specify a 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:: >>> import time @@ -605,6 +612,8 @@ '11/03/02' >>> d.strftime("%A %d. %B %Y") 'Monday 11. March 2002' + >>> '{} in {:%Y}'.format("John", d) + 'John in 2002' .. _datetime-datetime: @@ -1044,6 +1053,13 @@ string. See section :ref:`strftime-strptime-behavior`. +.. method:: datetime.__format__(format) + + Same as ``datetime.strftime``. This makes it possible to specify a format string + for a :class:`.datetime` object when using :meth:`str.format`. + See section :ref:`strftime-strptime-behavior`. + + Examples of working with datetime objects: .. doctest:: @@ -1088,6 +1104,8 @@ >>> # Formatting datetime >>> dt.strftime("%A, %d. %B %Y %I:%M%p") 'Tuesday, 21. November 2006 04:30PM' + >>> '{} in {:%Y}'.format("John", dt) + 'John in 2006' Using datetime with tzinfo: @@ -1268,6 +1286,13 @@ See section :ref:`strftime-strptime-behavior`. +.. method:: time.__format__(format) + + Same as ``time.strftime``. This makes it possible to specify a format string + for a :class:`.time` object when using :meth:`str.format`. + See section :ref:`strftime-strptime-behavior`. + + .. method:: time.utcoffset() If :attr:`tzinfo` is ``None``, returns ``None``, else returns @@ -1314,6 +1339,8 @@ 'Europe/Prague' >>> t.strftime("%H:%M:%S %Z") '12:10:30 Europe/Prague' + >>> '{} at {:%H:%M}'.format("John", t) + 'John at 12:10' .. _datetime-tzinfo: