Python Forum
looping through every strftime in HHMMSS format
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looping through every strftime in HHMMSS format
#1
How can I loop through every HHMMSS during a span of day? i.e. from 000001 to 235959. Can I use the strftime reference?
Reply
#2
for seconds in range(1, 235959):
    ...
Reply
#3
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.
Reply
#4
my answer fits your question:
Quote:i.e. from 000001 to 235959
Reply
#5
>>> 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))
Reply
#6
Here is another approach:-
import datetime

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  calling strftime does not display current time tonytech 2 2,084 May-05-2020, 04:53 AM
Last Post: tonytech
  time. strftime jor 1 2,455 Mar-13-2018, 02:51 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020