Connecting Tech Pros Worldwide Help | Site Map

drop 0 from hour/minute

Newbie
 
Join Date: Aug 2009
Posts: 4
#1: Aug 27 '09
Hi

looping within python resources..., I did not find a way to drop the 0 from hours/minutes. In fact I'd like to simply calculate the number of seconds since midnight so I did something like:

Expand|Select|Wrap|Line Numbers
  1. int(eval(time.strftime("%H*3600 + %M*60 + %S" , time.localtime())))
but obviously, that's failing when minute/hour look like 0x. It should work on any OS

Cheers
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,563
#2: Aug 27 '09

re: drop 0 from hour/minute


A straightforward way of calculating this would be to use the atributes of the time.struct_time object. Example:
Expand|Select|Wrap|Line Numbers
  1. >>> t = time.localtime()
  2. >>> t.tm_hour*3600+t.tm_min*60+t.tm_sec
  3. 40535
Reply