diff -r ab4432daf69f Doc/library/datetime.rst --- a/Doc/library/datetime.rst Mon Oct 22 21:50:27 2012 -0700 +++ b/Doc/library/datetime.rst Tue Oct 23 16:05:38 2012 +0300 @@ -597,6 +597,13 @@ section :ref:`strftime-strptime-behavior`. +.. method:: date.__format__(format) + + Same as ``date.strftime``. This makes it possible to specify an explicit + format string when using ``string.format``. + See section :ref:`strftime-strptime-behavior` + + Example of counting days to an event:: >>> import time @@ -647,6 +654,8 @@ '11/03/02' >>> d.strftime("%A %d. %B %Y") 'Monday 11. March 2002' + >>> '{0:%Y}'.format(d) + '2002' .. _datetime-datetime: @@ -1154,6 +1163,13 @@ string. See section :ref:`strftime-strptime-behavior`. +.. method:: datetime.__format__(format) + + Same as ``datetime.strftime``. This makes it possible to specify an explicit + format string when using ``string.format``. + See section :ref:`strftime-strptime-behavior`. + + Examples of working with datetime objects: .. doctest:: @@ -1198,6 +1214,8 @@ >>> # Formatting datetime >>> dt.strftime("%A, %d. %B %Y %I:%M%p") 'Tuesday, 21. November 2006 04:30PM' + >>> '{0:%Y}'.format(dt) + '2006' Using datetime with tzinfo: @@ -1385,6 +1403,13 @@ See section :ref:`strftime-strptime-behavior`. +.. method:: time.__format__(format) + + Same as ``time.strftime``. This makes it possible to specify an explicit + format string when using ``string.format``. + See section :ref:`strftime-strptime-behavior` + + .. method:: time.utcoffset() If :attr:`tzinfo` is ``None``, returns ``None``, else returns @@ -1431,6 +1456,8 @@ 'Europe/Prague' >>> t.strftime("%H:%M:%S %Z") '12:10:30 Europe/Prague' + >>> '{0:%Z}'.format(t) + 'Europe/Prague' .. _datetime-tzinfo: