Skip to content

Add total_seconds() method to datetime.time object #125435

@MirrorAzure

Description

@MirrorAzure

Feature or enhancement

Proposal:

It often happens that when working with datetime.time objects, user has to write custom constructions to get the number of seconds from the time object, like that:

>>> time_object = time(hour=5)
>>> total_seconds = time_object.hour * 3600 + time_object.minute * 60 + time_object.second
>>> print(total_seconds)
18000

It would be convenient to have a method that returns total number of seconds of time object
Example:

>>> time_object = time(hour=5)
>>> total_seconds = time_object.total_seconds()
>>> print(total_seconds)
18000

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions