@@ -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
@@ -314,16 +311,16 @@ systems.
314311
315312 If an argument outside those ranges is given, :exc: `ValueError ` is raised.
316313
317- Other constructors, all class methods:
318314
315+ Other constructors, all class methods:
319316
320- .. method :: date.today()
317+ .. classmethod :: date.today()
321318
322319 Return the current local date. This is equivalent to
323320 ``date.fromtimestamp(time.time()) ``.
324321
325322
326- .. method :: date.fromtimestamp(timestamp)
323+ .. classmethod :: date.fromtimestamp(timestamp)
327324
328325 Return the local date corresponding to the POSIX timestamp, such as is returned
329326 by :func: `time.time `. This may raise :exc: `ValueError `, if the timestamp is out
@@ -333,15 +330,15 @@ Other constructors, all class methods:
333330 timestamp, leap seconds are ignored by :meth: `fromtimestamp `.
334331
335332
336- .. method :: date.fromordinal(ordinal)
333+ .. classmethod :: date.fromordinal(ordinal)
337334
338335 Return the date corresponding to the proleptic Gregorian ordinal, where January
339336 1 of year 1 has ordinal 1. :exc: `ValueError ` is raised unless ``1 <= ordinal <=
340337 date.max.toordinal() ``. For any date *d *, ``date.fromordinal(d.toordinal()) ==
341338 d ``.
342339
343- Class attributes:
344340
341+ Class attributes:
345342
346343.. attribute :: date.min
347344
@@ -358,8 +355,8 @@ Class attributes:
358355 The smallest possible difference between non-equal date objects,
359356 ``timedelta(days=1) ``.
360357
361- Instance attributes (read-only):
362358
359+ Instance attributes (read-only):
363360
364361.. attribute :: date.year
365362
@@ -375,6 +372,7 @@ Instance attributes (read-only):
375372
376373 Between 1 and the number of days in the given month of the given year.
377374
375+
378376Supported operations:
379377
380378+-------------------------------+----------------------------------------------+
@@ -427,7 +425,6 @@ objects are considered to be true.
427425
428426Instance methods:
429427
430-
431428.. method :: date.replace(year, month, day)
432429
433430 Return a date with the same value, except for those members given new values by
@@ -507,7 +504,8 @@ Instance methods:
507504
508505 Return a string representing the date, controlled by an explicit format string.
509506 Format codes referring to hours, minutes or seconds will see 0 values. See
510- section :ref: `strftime-behavior `.
507+ section :ref: `strftime-strptime-behavior `.
508+
511509
512510Example of counting days to an event::
513511
@@ -574,7 +572,6 @@ both directions; like a time object, :class:`datetime` assumes there are exactly
574572
575573Constructor:
576574
577-
578575.. class :: datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
579576
580577 The year, month and day arguments are required. *tzinfo * may be ``None ``, or an
@@ -593,15 +590,14 @@ Constructor:
593590
594591Other constructors, all class methods:
595592
596-
597- .. method :: datetime.today()
593+ .. classmethod :: datetime.today()
598594
599595 Return the current local datetime, with :attr: `tzinfo ` ``None ``. This is
600596 equivalent to ``datetime.fromtimestamp(time.time()) ``. See also :meth: `now `,
601597 :meth: `fromtimestamp `.
602598
603599
604- .. method :: datetime.now(tz=None)
600+ .. classmethod :: datetime.now(tz=None)
605601
606602 Return the current local date and time. If optional argument *tz * is ``None ``
607603 or not specified, this is like :meth: `today `, but, if possible, supplies more
@@ -615,14 +611,14 @@ Other constructors, all class methods:
615611 See also :meth: `today `, :meth: `utcnow `.
616612
617613
618- .. method :: datetime.utcnow()
614+ .. classmethod :: datetime.utcnow()
619615
620616 Return the current UTC date and time, with :attr: `tzinfo ` ``None ``. This is like
621617 :meth: `now `, but returns the current UTC date and time, as a naive
622618 :class: `datetime ` object. See also :meth: `now `.
623619
624620
625- .. method :: datetime.fromtimestamp(timestamp, tz=None)
621+ .. classmethod :: datetime.fromtimestamp(timestamp, tz=None)
626622
627623 Return the local date and time corresponding to the POSIX timestamp, such as is
628624 returned by :func: `time.time `. If optional argument *tz * is ``None `` or not
@@ -643,7 +639,7 @@ Other constructors, all class methods:
643639 identical :class: `datetime ` objects. See also :meth: `utcfromtimestamp `.
644640
645641
646- .. method :: datetime.utcfromtimestamp(timestamp)
642+ .. classmethod :: datetime.utcfromtimestamp(timestamp)
647643
648644 Return the UTC :class: `datetime ` corresponding to the POSIX timestamp, with
649645 :attr: `tzinfo ` ``None ``. This may raise :exc: `ValueError `, if the timestamp is
@@ -652,15 +648,15 @@ Other constructors, all class methods:
652648 :meth: `fromtimestamp `.
653649
654650
655- .. method :: datetime.fromordinal(ordinal)
651+ .. classmethod :: datetime.fromordinal(ordinal)
656652
657653 Return the :class: `datetime ` corresponding to the proleptic Gregorian ordinal,
658654 where January 1 of year 1 has ordinal 1. :exc: `ValueError ` is raised unless ``1
659655 <= ordinal <= datetime.max.toordinal() ``. The hour, minute, second and
660656 microsecond of the result are all 0, and :attr: `tzinfo ` is ``None ``.
661657
662658
663- .. method :: datetime.combine(date, time)
659+ .. classmethod :: datetime.combine(date, time)
664660
665661 Return a new :class: `datetime ` object whose date members are equal to the given
666662 :class: `date ` object's, and whose time and :attr: `tzinfo ` members are equal to
@@ -669,17 +665,17 @@ Other constructors, all class methods:
669665 object, its time and :attr: `tzinfo ` members are ignored.
670666
671667
672- .. method :: datetime.strptime(date_string, format)
668+ .. classmethod :: datetime.strptime(date_string, format)
673669
674670 Return a :class: `datetime ` corresponding to *date_string *, parsed according to
675671 *format *. This is equivalent to ``datetime(*(time.strptime(date_string,
676672 format)[0:6])) ``. :exc: `ValueError ` is raised if the date_string and format
677673 can't be parsed by :func: `time.strptime ` or if it returns a value which isn't a
678- time tuple.
674+ time tuple. See section :ref: ` strftime-strptime-behavior `.
679675
680676
681- Class attributes:
682677
678+ Class attributes:
683679
684680.. attribute :: datetime.min
685681
@@ -698,8 +694,8 @@ Class attributes:
698694 The smallest possible difference between non-equal :class: `datetime ` objects,
699695 ``timedelta(microseconds=1) ``.
700696
701- Instance attributes (read-only):
702697
698+ Instance attributes (read-only):
703699
704700.. attribute :: datetime.year
705701
@@ -741,6 +737,7 @@ Instance attributes (read-only):
741737 The object passed as the *tzinfo * argument to the :class: `datetime ` constructor,
742738 or ``None `` if none was passed.
743739
740+
744741Supported operations:
745742
746743+---------------------------------------+-------------------------------+
@@ -814,7 +811,6 @@ all :class:`datetime` objects are considered to be true.
814811
815812Instance methods:
816813
817-
818814.. method :: datetime.date()
819815
820816 Return :class: `date ` object with same year, month and day.
@@ -992,7 +988,8 @@ Instance methods:
992988.. method :: datetime.strftime(format)
993989
994990 Return a string representing the date and time, controlled by an explicit format
995- string. See section :ref: `strftime-behavior `.
991+ string. See section :ref: `strftime-strptime-behavior `.
992+
996993
997994Examples of working with datetime objects:
998995
@@ -1105,7 +1102,6 @@ Using datetime with tzinfo:
11051102A time object represents a (local) time of day, independent of any particular
11061103day, and subject to adjustment via a :class: `tzinfo ` object.
11071104
1108-
11091105.. class :: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
11101106
11111107 All arguments are optional. *tzinfo * may be ``None ``, or an instance of a
@@ -1139,8 +1135,8 @@ Class attributes:
11391135 ``timedelta(microseconds=1) ``, although note that arithmetic on :class: `time `
11401136 objects is not supported.
11411137
1142- Instance attributes (read-only):
11431138
1139+ Instance attributes (read-only):
11441140
11451141.. attribute :: time.hour
11461142
@@ -1167,6 +1163,7 @@ Instance attributes (read-only):
11671163 The object passed as the tzinfo argument to the :class: `time ` constructor, or
11681164 ``None `` if none was passed.
11691165
1166+
11701167Supported operations:
11711168
11721169* comparison of :class: `time ` to :class: `time `, where *a * is considered less
@@ -1189,8 +1186,8 @@ Supported operations:
11891186 only if, after converting it to minutes and subtracting :meth: `utcoffset ` (or
11901187 ``0 `` if that's ``None ``), the result is non-zero.
11911188
1192- Instance methods:
11931189
1190+ Instance methods:
11941191
11951192.. method :: time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]])
11961193
@@ -1216,7 +1213,7 @@ Instance methods:
12161213.. method :: time.strftime(format)
12171214
12181215 Return a string representing the time, controlled by an explicit format string.
1219- See section :ref: `strftime-behavior `.
1216+ See section :ref: `strftime-strptime- behavior `.
12201217
12211218
12221219.. method :: time.utcoffset()
@@ -1241,6 +1238,7 @@ Instance methods:
12411238 ``self.tzinfo.tzname(None) ``, or raises an exception if the latter doesn't
12421239 return ``None `` or a string object.
12431240
1241+
12441242Example:
12451243
12461244 >>> from datetime import time, tzinfo
@@ -1377,6 +1375,7 @@ methods. Exactly which methods are needed depends on the uses made of aware
13771375
13781376 The default implementation of :meth: `tzname ` raises :exc: `NotImplementedError `.
13791377
1378+
13801379These methods are called by a :class: `datetime ` or :class: `time ` object, in
13811380response to their methods of the same names. A :class: `datetime ` object passes
13821381itself as the argument, and a :class: `time ` object passes ``None `` as the
@@ -1480,20 +1479,25 @@ other fixed-offset :class:`tzinfo` subclass (such as a class representing only
14801479EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
14811480
14821481
1483- .. _strftime-behavior :
1482+ .. _strftime-strptime- behavior :
14841483
1485- :meth: `strftime ` Behavior
1486- -------------------------
1484+ :meth: `strftime ` and :meth: ` strptime ` Behavior
1485+ ----------------------------------------------
14871486
14881487:class: `date `, :class: `datetime `, and :class: `time ` objects all support a
14891488``strftime(format) `` method, to create a string representing the time under the
14901489control of an explicit format string. Broadly speaking, ``d.strftime(fmt) ``
14911490acts like the :mod: `time ` module's ``time.strftime(fmt, d.timetuple()) ``
14921491although not all objects support a :meth: `timetuple ` method.
14931492
1493+ Conversely, the :meth: `datetime.strptime ` class method creates a
1494+ :class: `datetime ` object from a string representing a date and time and a
1495+ corresponding format string. ``datetime.strptime(date_string, format) `` is
1496+ equivalent to ``datetime(*(time.strptime(date_string, format)[0:6])) ``.
1497+
14941498For :class: `time ` objects, the format codes for year, month, and day should not
14951499be used, as time objects have no such values. If they're used anyway, ``1900 ``
1496- is substituted for the year, and ``0 `` for the month and day.
1500+ is substituted for the year, and ``1 `` for the month and day.
14971501
14981502For :class: `date ` objects, the format codes for hours, minutes, seconds, and
14991503microseconds should not be used, as :class: `date ` objects have no such
@@ -1615,26 +1619,26 @@ platforms. Regardless of platform, years before 1900 cannot be used.
16151619Notes:
16161620
16171621(1)
1618- When used with the :func : `strptime ` function , the ``%f `` directive
1622+ When used with the :meth : `strptime ` method , the ``%f `` directive
16191623 accepts from one to six digits and zero pads on the right. ``%f `` is
16201624 an extension to the set of format characters in the C standard (but
16211625 implemented separately in datetime objects, and therefore always
16221626 available).
16231627
16241628(2)
1625- When used with the :func : `strptime ` function , the ``%p `` directive only affects
1629+ When used with the :meth : `strptime ` method , the ``%p `` directive only affects
16261630 the output hour field if the ``%I `` directive is used to parse the hour.
16271631
16281632(3)
16291633 The range really is ``0 `` to ``61 ``; according to the Posix standard this
16301634 accounts for leap seconds and the (very rare) double leap seconds.
16311635 The :mod: `time ` module may produce and does accept leap seconds since
16321636 it is based on the Posix standard, but the :mod: `datetime ` module
1633- does not accept leap seconds in :func : `strptime ` input nor will it
1637+ does not accept leap seconds in :meth : `strptime ` input nor will it
16341638 produce them in :func: `strftime ` output.
16351639
16361640(4)
1637- When used with the :func : `strptime ` function , ``%U `` and ``%W `` are only used in
1641+ When used with the :meth : `strptime ` method , ``%U `` and ``%W `` are only used in
16381642 calculations when the day of the week and the year are specified.
16391643
16401644(5)
0 commit comments