~ubuntu-branches/ubuntu/saucy/python2.7/saucy-proposed

« back to all changes in this revision

Viewing changes to Doc/library/datetime.rst

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-05-15 19:15:16 UTC
  • mto: (36.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: package-import@ubuntu.com-20130515191516-zmv6to904wemey7s
Tags: upstream-2.7.5
ImportĀ upstreamĀ versionĀ 2.7.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
555
555
   section :ref:`strftime-strptime-behavior`.
556
556
 
557
557
 
 
558
.. method:: date.__format__(format)
 
559
 
 
560
   Same as :meth:`.date.strftime`. This makes it possible to specify format
 
561
   string for a :class:`.date` object when using :meth:`str.format`.
 
562
   See section :ref:`strftime-strptime-behavior`.
 
563
 
 
564
 
558
565
Example of counting days to an event::
559
566
 
560
567
    >>> import time
605
612
    '11/03/02'
606
613
    >>> d.strftime("%A %d. %B %Y")
607
614
    'Monday 11. March 2002'
 
615
    >>> 'The {1} is {0:%d}, the {2} is {0:%B}.'.format(d, "day", "month")
 
616
    'The day is 11, the month is March.'
608
617
 
609
618
 
610
619
.. _datetime-datetime:
1044
1053
   string.  See section :ref:`strftime-strptime-behavior`.
1045
1054
 
1046
1055
 
 
1056
.. method:: datetime.__format__(format)
 
1057
 
 
1058
   Same as :meth:`.datetime.strftime`.  This makes it possible to specify format
 
1059
   string for a :class:`.datetime` object when using :meth:`str.format`.
 
1060
   See section :ref:`strftime-strptime-behavior`.
 
1061
 
 
1062
 
1047
1063
Examples of working with datetime objects:
1048
1064
 
1049
1065
.. doctest::
1088
1104
    >>> # Formatting datetime
1089
1105
    >>> dt.strftime("%A, %d. %B %Y %I:%M%p")
1090
1106
    'Tuesday, 21. November 2006 04:30PM'
 
1107
    >>> 'The {1} is {0:%d}, the {2} is {0:%B}, the {3} is {0:%I:%M%p}.'.format(dt, "day", "month", "time")
 
1108
    'The day is 21, the month is November, the time is 04:30PM.'
1091
1109
 
1092
1110
Using datetime with tzinfo:
1093
1111
 
1268
1286
   See section :ref:`strftime-strptime-behavior`.
1269
1287
 
1270
1288
 
 
1289
.. method:: time.__format__(format)
 
1290
 
 
1291
   Same as :meth:`.time.strftime`. This makes it possible to specify format string
 
1292
   for a :class:`.time` object when using :meth:`str.format`.
 
1293
   See section :ref:`strftime-strptime-behavior`.
 
1294
 
 
1295
 
1271
1296
.. method:: time.utcoffset()
1272
1297
 
1273
1298
   If :attr:`tzinfo` is ``None``, returns ``None``, else returns
1314
1339
    'Europe/Prague'
1315
1340
    >>> t.strftime("%H:%M:%S %Z")
1316
1341
    '12:10:30 Europe/Prague'
 
1342
    >>> 'The {} is {:%H:%M}.'.format("time", t)
 
1343
    'The time is 12:10.'
1317
1344
 
1318
1345
 
1319
1346
.. _datetime-tzinfo: