>>> a = str(datetime.now())
>>> a
'2012-03-22 11:16:11.343000'
I need to get a string like that: '16:11.34'.
Should be as compact as possible.
Or should I use time() instead?
How do I get it?
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.
What about:
datetime.now().strftime('%M:%S.%f')[:-4]I’m not sure what you mean by “Milliseconds only 2 digits”, but this should keep it to 2 decimal places. There may be a more elegant way by manipulating the strftime format string to cut down on the precision as well — I’m not completely sure.
EDIT
If the
%fmodifier doesn’t work for you, you can try something like:Again, I’m assuming you just want to truncate the precision.