diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 23:02:32 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 23:02:32 (GMT) |
commit | be6859d877193004781c5b0b69f87b3ab5704ea1 (patch) | |
tree | 1a8448b965063fcea20203bfd949f215034155c0 /Doc/library | |
parent | 7d7aede558bc93196a40bd00fd857f57d00dd5bc (diff) | |
download | cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.zip cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.tar.gz cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.tar.bz2 |
Merged revisions 76529 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76529 | antoine.pitrou | 2009-11-25 23:59:36 +0100 (mer., 25 nov. 2009) | 4 lines
Issue #5788: `datetime.timedelta` objects get a new `total_seconds()` method returning
the total number of seconds in the duration. Patch by Brian Quinlan.
........
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/datetime.rst | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 68ae586..5126821 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -267,12 +267,24 @@ comparison is ``==`` or ``!=``. The latter cases return :const:`False` or efficient pickling, and in Boolean contexts, a :class:`timedelta` object is considered to be true if and only if it isn't equal to ``timedelta(0)``. +Instance methods: + +.. method:: timedelta.total_seconds() + + Return the total number of seconds contained in the duration. Equivalent to + ``td.microseconds / 1000000 + td.seconds + td.days * 24 * 3600``. + + .. versionadded:: 3.2 + + Example usage: >>> from datetime import timedelta >>> year = timedelta(days=365) >>> another_year = timedelta(weeks=40, days=84, hours=23, ... minutes=50, seconds=600) # adds up to 365 days + >>> year.total_seconds() + 31536000.0 >>> year == another_year True >>> ten_years = 10 * year |