I wanted to format this string but I don't know how I can do the formatting part at all.
class MyTime:
def __init__(self, hrs=0, mins=0, secs=0):
self.hours = hrs
self.minutes = mins
self.seconds = secs
if self.seconds >= 60:
self.minutes += self.seconds // 60
self.seconds = self.seconds % 60
if self.minutes >= 60:
self.hours += self.minutes // 60
self.minutes = self.minutes % 60
if self.hours >= 24:
self.hours = self.hours % 24
def get_sec(self):
return (self.hours * 60 + self.minutes) * 60 + self.seconds
def __str__(self):
return "{:02d}:{:02d}:{:02d}".\
format(self.hours, self.minutes, self.seconds)
def increment(self, t):
totalsec = self.get_sec() + t
return totalsec
def between(t1, t3, t2):
return t1.get_sec() <= t3.get_sec() <= t2.get_sec()
t1 = MyTime(9, 59, 59)
t2 = MyTime(10, 0, 1)
t3 = MyTime(10, 0, 0)
print (t1.increment(300))
print (t1.increment(-300))
I want to format it with something like this:
"{:02d}:{:02d}:{:02d}".\
format(self.hours, self.minutes, self.seconds
Any help would be great.