Date time python


#1

“”"
from datetime import datetime
now = datetime.now()

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

“”"

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


#2

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


#3

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


#4

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


#5

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