Standard class for time *period*?

Loris Bennett loris.bennett at fu-berlin.de
Mon Mar 27 10:20:06 EDT 2023


ram at zedat.fu-berlin.de (Stefan Ram) writes:

> ram at zedat.fu-berlin.de (Stefan Ram) writes:
>>d = datetime_diff.days
>>h, rem = divmod( datetime_diff.seconds, 3600 )
>>m, s = divmod( rem, 60 )
>>print( f'{d:02}-{h:02}:{m:02}:{s:02}' )
>
>   If the default formatting is acceptable to you, you can also
>   print the datetime_diff in a shorter way:
>
>   main.py
>
> from datetime import datetime
>
> format = '%Y-%m-%dT%H:%M:%S%z'
> datetime_0 = datetime.strptime( '2023-03-27T14:00:52+01:00', format )
> datetime_1 = datetime.strptime( '2023-03-27T14:27:23+01:00', format )
>
> print( datetime_1 - datetime_0 )
>
>   sys.stdout
>
> 0:26:31
>
>   . Days will also be shown if greater than zero.

Thanks for the examples, but I am not really interested in how to write
a bunch of code to do what I need, as I can already do that.  I am
interested in whether there is a standard class for this and, if there is
not such a class, why this is the case.

Cheers,

Loris

-- 
This signature is currently under constuction.


More information about the Python-list mailing list