Getting a lists of times in Python from 0:0:0 to 23:59:59 and then comparing with datetime values -
i working on code generate time entire day 30 second intervals. tried using dt.datetime , dt.time end either datetime value or timedelta value (0,2970). can please tell me how this.
so need list has data like:
[00:00:00] [00:00:01] [00:00:02]
till [23:59:59] , needed compare against datetime value 6/23/2011 6:38:00 am.
thanks!
is there reason want use datetimes instead of 3 loops counting up? similarly, want fancy or want compare against time? if don't need account leap seconds or that, easy way.
import datetime = datetime.datetime.now() h in xrange(24): m in xrange(60): s in xrange(60): time_string = '%02d:%02d:%02d' % (h,m,s) if time_string == now.strftime('%h:%m:%s'): print 'you found it! %s' % time_string
can give more info why doing this? seems much better off parsing datetimes or using strftime need instead of looping through 60*60*24 times.
Comments
Post a Comment