diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 78e03e32896740..86c9805b6e008e 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -1392,6 +1392,7 @@ class time: utcoffset() tzname() dst() + total_seconds() Properties (readonly): hour, minute, second, microsecond, tzinfo, fold @@ -1473,6 +1474,11 @@ def tzinfo(self): def fold(self): return self._fold + def total_seconds(self): + """Total seconds in the time.""" + return ((self.hour * 3600 + self.minute * 60 + self.second) * 10**6 + + self.microsecond) / 10**6 + # Standard conversions, __hash__ (and helpers) # Comparisons of time objects with other. diff --git a/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst b/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst new file mode 100644 index 00000000000000..5a8db84b6c3813 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst @@ -0,0 +1 @@ +Add :meth:`datetime.time.total_seconds` method