0

I want to generate a timestamp only in hour and minutes format, like this:

154h 27m

Please check my logic below

planned_downtime = timedelta(hours=random.randrange(150))

However, the result is coming in seconds. To convert it to above mentioned format, I applied this:

planned_downtime.strftime("%H %M")

But I'm getting errors. How can I convert this randomly generated time in above format?

Suraj221b
  • 112
  • 7
  • Question got closed but use this `print(f"{planned_downtime.seconds // 3600}h {planned_downtime.seconds // 60 % 60}m")` – LTJ Oct 07 '22 at 13:05

1 Answers1

0

Like this maybe:

m = random.randint(0,60)
h = random.randint(0,24)
ts = f'{h}h {m}m'

print(ts)
15h 48m
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432