Date time python


from datetime import datetime
now =

print ‘%02d/%02d/%04d’ % (now.month,, now.year)


I am really confused about the all that" 0, 2, 4 and d ". what and why are they?


they indicate the amount of digits. So you know day and month will be 2 digits, while the year will be 4 digits. Quite handy


before comma*
there’s nothing after, %d formats as integer (decimal integer, decimal as in base10, as opposed to hexadecimal, binary, octal)


yep, you are right. Oops, i was confused with %f, i should pay more attention


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