Because Python really just calls the C language strftime(3)
function on your platform, it might be that there are format characters you could use to control the leading zero; try man strftime
and take a look. But, of course, the result will not be portable, as the Python manual will remind you. :-)
I would try using a new-style datetime
object instead, which has attributes like t.year
and t.month
and t.day
, and put those through the normal, high-powered formatting of the %
operator, which does support control of leading zeros. See http://docs.python.org/library/datetime.html for details. Better yet, use the "".format()
operator if your Python has it and be even more modern; it has lots of format options for numbers as well. See: http://docs.python.org/library/string.html#string-formatting.