is cutting off the zero's from the hour/seconds


So my current time when I run datetime is 00:41:07.xxxx
When I try to print the exercise, I’m getting the following:

0:41:7 instead of 00:41:07.

I guess it’s just cutting off those zeroes since 07 is the same as 7 in normal number land, but not with time. How do I get those zeroes back?

I tried to turn now.hour and now.second into strings and print those instead, but that didn’t work.

second = str(now.second)
hour = str(now.hour)
print "%s:%s:%s" % (hour, now.minute, second) 


Hi @kyrafetrow,

Try this for a better format, padded with leading zeroes where needed …

print '%4d/%02d/%02d %02d:%02d:%02d' % (now.year, now.month,, now.hour, now.minute, now.second)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.