Python Forum

Full Version: looping through every strftime in HHMMSS format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I loop through every HHMMSS during a span of day? i.e. from 000001 to 235959. Can I use the strftime reference?
for seconds in range(1, 235959):
    ...
Thanks for the response. However this line will iterate 235959 times which is incorrect. Over a span of a day i.e.24 hours, HHMMSS will have only 24*60*60=86400 values.
my answer fits your question:
Quote:i.e. from 000001 to 235959
>>> for hh in range(24):
...   for mm in range(60):
...     for ss in range(60):
...       print("{:02.0f}{:02.0f}{:02.0f}".format(hh, mm, ss))
Here is another approach:-
import datetime

for i in range(86400):
    print(datetime.timedelta(seconds=i))