@@ -36,7 +36,6 @@ than rational, and there is no standard suitable for every application.
3636
3737The :mod: `datetime ` module exports the following constants:
3838
39-
4039.. data :: MINYEAR
4140
4241 The smallest year number allowed in a :class: `date ` or :class: `datetime ` object.
@@ -61,7 +60,6 @@ The :mod:`datetime` module exports the following constants:
6160Available Types
6261---------------
6362
64-
6563.. class :: date
6664 :noindex:
6765
@@ -131,7 +129,6 @@ Subclass relationships::
131129A :class: `timedelta ` object represents a duration, the difference between two
132130dates or times.
133131
134-
135132.. class :: timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
136133
137134 All arguments are optional and default to ``0 ``. Arguments may be integers
@@ -168,8 +165,8 @@ dates or times.
168165 >>> (d.days, d.seconds, d.microseconds)
169166 (-1, 86399, 999999)
170167
171- Class attributes are:
172168
169+ Class attributes are:
173170
174171.. attribute :: timedelta.min
175172
@@ -326,16 +323,16 @@ systems.
326323
327324 If an argument outside those ranges is given, :exc: `ValueError ` is raised.
328325
329- Other constructors, all class methods:
330326
327+ Other constructors, all class methods:
331328
332- .. method :: date.today()
329+ .. classmethod :: date.today()
333330
334331 Return the current local date. This is equivalent to
335332 ``date.fromtimestamp(time.time()) ``.
336333
337334
338- .. method :: date.fromtimestamp(timestamp)
335+ .. classmethod :: date.fromtimestamp(timestamp)
339336
340337 Return the local date corresponding to the POSIX timestamp, such as is returned
341338 by :func: `time.time `. This may raise :exc: `ValueError `, if the timestamp is out
@@ -345,15 +342,15 @@ Other constructors, all class methods:
345342 timestamp, leap seconds are ignored by :meth: `fromtimestamp `.
346343
347344
348- .. method :: date.fromordinal(ordinal)
345+ .. classmethod :: date.fromordinal(ordinal)
349346
350347 Return the date corresponding to the proleptic Gregorian ordinal, where January
351348 1 of year 1 has ordinal 1. :exc: `ValueError ` is raised unless ``1 <= ordinal <=
352349 date.max.toordinal() ``. For any date *d *, ``date.fromordinal(d.toordinal()) ==
353350 d ``.
354351
355- Class attributes:
356352
353+ Class attributes:
357354
358355.. attribute :: date.min
359356
@@ -370,8 +367,8 @@ Class attributes:
370367 The smallest possible difference between non-equal date objects,
371368 ``timedelta(days=1) ``.
372369
373- Instance attributes (read-only):
374370
371+ Instance attributes (read-only):
375372
376373.. attribute :: date.year
377374
@@ -387,6 +384,7 @@ Instance attributes (read-only):
387384
388385 Between 1 and the number of days in the given month of the given year.
389386
387+
390388Supported operations:
391389
392390+-------------------------------+----------------------------------------------+
@@ -439,7 +437,6 @@ objects are considered to be true.
439437
440438Instance methods:
441439
442-
443440.. method :: date.replace(year, month, day)
444441
445442 Return a date with the same value, except for those members given new values by
@@ -519,7 +516,8 @@ Instance methods:
519516
520517 Return a string representing the date, controlled by an explicit format string.
521518 Format codes referring to hours, minutes or seconds will see 0 values. See
522- section :ref: `strftime-behavior `.
519+ section :ref: `strftime-strptime-behavior `.
520+
523521
524522Example of counting days to an event::
525523
@@ -586,7 +584,6 @@ both directions; like a time object, :class:`datetime` assumes there are exactly
586584
587585Constructor:
588586
589-
590587.. class :: datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
591588
592589 The year, month and day arguments are required. *tzinfo * may be ``None ``, or an
@@ -605,15 +602,14 @@ Constructor:
605602
606603Other constructors, all class methods:
607604
608-
609- .. method :: datetime.today()
605+ .. classmethod :: datetime.today()
610606
611607 Return the current local datetime, with :attr: `tzinfo ` ``None ``. This is
612608 equivalent to ``datetime.fromtimestamp(time.time()) ``. See also :meth: `now `,
613609 :meth: `fromtimestamp `.
614610
615611
616- .. method :: datetime.now(tz=None)
612+ .. classmethod :: datetime.now(tz=None)
617613
618614 Return the current local date and time. If optional argument *tz * is ``None ``
619615 or not specified, this is like :meth: `today `, but, if possible, supplies more
@@ -627,14 +623,14 @@ Other constructors, all class methods:
627623 See also :meth: `today `, :meth: `utcnow `.
628624
629625
630- .. method :: datetime.utcnow()
626+ .. classmethod :: datetime.utcnow()
631627
632628 Return the current UTC date and time, with :attr: `tzinfo ` ``None ``. This is like
633629 :meth: `now `, but returns the current UTC date and time, as a naive
634630 :class: `datetime ` object. See also :meth: `now `.
635631
636632
637- .. method :: datetime.fromtimestamp(timestamp, tz=None)
633+ .. classmethod :: datetime.fromtimestamp(timestamp, tz=None)
638634
639635 Return the local date and time corresponding to the POSIX timestamp, such as is
640636 returned by :func: `time.time `. If optional argument *tz * is ``None `` or not
@@ -655,7 +651,7 @@ Other constructors, all class methods:
655651 identical :class: `datetime ` objects. See also :meth: `utcfromtimestamp `.
656652
657653
658- .. method :: datetime.utcfromtimestamp(timestamp)
654+ .. classmethod :: datetime.utcfromtimestamp(timestamp)
659655
660656 Return the UTC :class: `datetime ` corresponding to the POSIX timestamp, with
661657 :attr: `tzinfo ` ``None ``. This may raise :exc: `ValueError `, if the timestamp is
@@ -664,15 +660,15 @@ Other constructors, all class methods:
664660 :meth: `fromtimestamp `.
665661
666662
667- .. method :: datetime.fromordinal(ordinal)
663+ .. classmethod :: datetime.fromordinal(ordinal)
668664
669665 Return the :class: `datetime ` corresponding to the proleptic Gregorian ordinal,
670666 where January 1 of year 1 has ordinal 1. :exc: `ValueError ` is raised unless ``1
671667 <= ordinal <= datetime.max.toordinal() ``. The hour, minute, second and
672668 microsecond of the result are all 0, and :attr: `tzinfo ` is ``None ``.
673669
674670
675- .. method :: datetime.combine(date, time)
671+ .. classmethod :: datetime.combine(date, time)
676672
677673 Return a new :class: `datetime ` object whose date members are equal to the given
678674 :class: `date ` object's, and whose time and :attr: `tzinfo ` members are equal to
@@ -681,17 +677,17 @@ Other constructors, all class methods:
681677 object, its time and :attr: `tzinfo ` members are ignored.
682678
683679
684- .. method :: datetime.strptime(date_string, format)
680+ .. classmethod :: datetime.strptime(date_string, format)
685681
686682 Return a :class: `datetime ` corresponding to *date_string *, parsed according to
687683 *format *. This is equivalent to ``datetime(*(time.strptime(date_string,
688684 format)[0:6])) ``. :exc: `ValueError ` is raised if the date_string and format
689685 can't be parsed by :func: `time.strptime ` or if it returns a value which isn't a
690- time tuple.
686+ time tuple. See section :ref: ` strftime-strptime-behavior `.
691687
692688
693- Class attributes:
694689
690+ Class attributes:
695691
696692.. attribute :: datetime.min
697693
@@ -710,8 +706,8 @@ Class attributes:
710706 The smallest possible difference between non-equal :class: `datetime ` objects,
711707 ``timedelta(microseconds=1) ``.
712708
713- Instance attributes (read-only):
714709
710+ Instance attributes (read-only):
715711
716712.. attribute :: datetime.year
717713
@@ -753,6 +749,7 @@ Instance attributes (read-only):
753749 The object passed as the *tzinfo * argument to the :class: `datetime ` constructor,
754750 or ``None `` if none was passed.
755751
752+
756753Supported operations:
757754
758755+---------------------------------------+-------------------------------+
@@ -826,7 +823,6 @@ all :class:`datetime` objects are considered to be true.
826823
827824Instance methods:
828825
829-
830826.. method :: datetime.date()
831827
832828 Return :class: `date ` object with same year, month and day.
@@ -1004,7 +1000,8 @@ Instance methods:
10041000.. method :: datetime.strftime(format)
10051001
10061002 Return a string representing the date and time, controlled by an explicit format
1007- string. See section :ref: `strftime-behavior `.
1003+ string. See section :ref: `strftime-strptime-behavior `.
1004+
10081005
10091006Examples of working with datetime objects:
10101007
@@ -1117,7 +1114,6 @@ Using datetime with tzinfo:
11171114A time object represents a (local) time of day, independent of any particular
11181115day, and subject to adjustment via a :class: `tzinfo ` object.
11191116
1120-
11211117.. class :: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
11221118
11231119 All arguments are optional. *tzinfo * may be ``None ``, or an instance of a
@@ -1151,8 +1147,8 @@ Class attributes:
11511147 ``timedelta(microseconds=1) ``, although note that arithmetic on :class: `time `
11521148 objects is not supported.
11531149
1154- Instance attributes (read-only):
11551150
1151+ Instance attributes (read-only):
11561152
11571153.. attribute :: time.hour
11581154
@@ -1179,6 +1175,7 @@ Instance attributes (read-only):
11791175 The object passed as the tzinfo argument to the :class: `time ` constructor, or
11801176 ``None `` if none was passed.
11811177
1178+
11821179Supported operations:
11831180
11841181* comparison of :class: `time ` to :class: `time `, where *a * is considered less
@@ -1201,8 +1198,8 @@ Supported operations:
12011198 only if, after converting it to minutes and subtracting :meth: `utcoffset ` (or
12021199 ``0 `` if that's ``None ``), the result is non-zero.
12031200
1204- Instance methods:
12051201
1202+ Instance methods:
12061203
12071204.. method :: time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]])
12081205
@@ -1228,7 +1225,7 @@ Instance methods:
12281225.. method :: time.strftime(format)
12291226
12301227 Return a string representing the time, controlled by an explicit format string.
1231- See section :ref: `strftime-behavior `.
1228+ See section :ref: `strftime-strptime- behavior `.
12321229
12331230
12341231.. method :: time.utcoffset()
@@ -1253,6 +1250,7 @@ Instance methods:
12531250 ``self.tzinfo.tzname(None) ``, or raises an exception if the latter doesn't
12541251 return ``None `` or a string object.
12551252
1253+
12561254Example:
12571255
12581256 >>> from datetime import time, tzinfo
@@ -1389,6 +1387,7 @@ methods. Exactly which methods are needed depends on the uses made of aware
13891387
13901388 The default implementation of :meth: `tzname ` raises :exc: `NotImplementedError `.
13911389
1390+
13921391These methods are called by a :class: `datetime ` or :class: `time ` object, in
13931392response to their methods of the same names. A :class: `datetime ` object passes
13941393itself as the argument, and a :class: `time ` object passes ``None `` as the
@@ -1492,20 +1491,25 @@ other fixed-offset :class:`tzinfo` subclass (such as a class representing only
14921491EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
14931492
14941493
1495- .. _strftime-behavior :
1494+ .. _strftime-strptime- behavior :
14961495
1497- :meth: `strftime ` Behavior
1498- -------------------------
1496+ :meth: `strftime ` and :meth: ` strptime ` Behavior
1497+ ----------------------------------------------
14991498
15001499:class: `date `, :class: `datetime `, and :class: `time ` objects all support a
15011500``strftime(format) `` method, to create a string representing the time under the
15021501control of an explicit format string. Broadly speaking, ``d.strftime(fmt) ``
15031502acts like the :mod: `time ` module's ``time.strftime(fmt, d.timetuple()) ``
15041503although not all objects support a :meth: `timetuple ` method.
15051504
1505+ Conversely, the :meth: `datetime.strptime ` class method creates a
1506+ :class: `datetime ` object from a string representing a date and time and a
1507+ corresponding format string. ``datetime.strptime(date_string, format) `` is
1508+ equivalent to ``datetime(*(time.strptime(date_string, format)[0:6])) ``.
1509+
15061510For :class: `time ` objects, the format codes for year, month, and day should not
15071511be used, as time objects have no such values. If they're used anyway, ``1900 ``
1508- is substituted for the year, and ``0 `` for the month and day.
1512+ is substituted for the year, and ``1 `` for the month and day.
15091513
15101514For :class: `date ` objects, the format codes for hours, minutes, seconds, and
15111515microseconds should not be used, as :class: `date ` objects have no such
@@ -1627,26 +1631,26 @@ platforms. Regardless of platform, years before 1900 cannot be used.
16271631Notes:
16281632
16291633(1)
1630- When used with the :func : `strptime ` function , the ``%f `` directive
1634+ When used with the :meth : `strptime ` method , the ``%f `` directive
16311635 accepts from one to six digits and zero pads on the right. ``%f `` is
16321636 an extension to the set of format characters in the C standard (but
16331637 implemented separately in datetime objects, and therefore always
16341638 available).
16351639
16361640(2)
1637- When used with the :func : `strptime ` function , the ``%p `` directive only affects
1641+ When used with the :meth : `strptime ` method , the ``%p `` directive only affects
16381642 the output hour field if the ``%I `` directive is used to parse the hour.
16391643
16401644(3)
16411645 The range really is ``0 `` to ``61 ``; according to the Posix standard this
16421646 accounts for leap seconds and the (very rare) double leap seconds.
16431647 The :mod: `time ` module may produce and does accept leap seconds since
16441648 it is based on the Posix standard, but the :mod: `datetime ` module
1645- does not accept leap seconds in :func : `strptime ` input nor will it
1649+ does not accept leap seconds in :meth : `strptime ` input nor will it
16461650 produce them in :func: `strftime ` output.
16471651
16481652(4)
1649- When used with the :func : `strptime ` function , ``%U `` and ``%W `` are only used in
1653+ When used with the :meth : `strptime ` method , ``%U `` and ``%W `` are only used in
16501654 calculations when the day of the week and the year are specified.
16511655
16521656(5)
0 commit comments