Python Forum
looping through every strftime in HHMMSS format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: looping through every strftime in HHMMSS format (/thread-4767.html)



looping through every strftime in HHMMSS format - yatinydalvi - Sep-07-2017

How can I loop through every HHMMSS during a span of day? i.e. from 000001 to 235959. Can I use the strftime reference?


RE: looping through every strftime in HHMMSS format - Larz60+ - Sep-07-2017

for seconds in range(1, 235959):
    ...



RE: looping through every strftime in HHMMSS format - yatinydalvi - Sep-07-2017

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.


RE: looping through every strftime in HHMMSS format - Larz60+ - Sep-07-2017

my answer fits your question:
Quote:i.e. from 000001 to 235959



RE: looping through every strftime in HHMMSS format - nilamo - Sep-28-2017

>>> 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))



RE: looping through every strftime in HHMMSS format - Yoda - Sep-28-2017

Here is another approach:-
import datetime

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