I have a simple script:
now = datetime.datetime.now()
print "%d%d%d%d%d" % ( now.year, now.month, now.day, now.hour, now.minute )
result:
20111124149
How to get result:
201111241409
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Specify that the numbers should have width two and be zero-padded:
If we break one of the components down, we get:
%marks the start of a substitution target.0makes the result zero-padded.2means, that the result should be 2 characters wide.dmeans that it’s a decimal value.Further information: