Is there in Python data structure to represent only hour minute and second without another info, if not then what structure is best to use in my case?
The datetime
module offers several types to represent dates and time, the datetime.time()
object may fit your needs here:
from datetime import time
afternoon_tea = time(16, 30)
If you are trying to represent durations, you can use datetime.timedelta()
objects; these can be used to adjust datetime.date()
or datetime.datetime()
objects:
from datetime import timedelta
halfday = timedelta(hours=12)
You could also just represent your time as an integer, representing seconds:
onehour = 60
This all depends on your use cases, which you didn't include in your question, unfortunately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With