21

I am reading the official documentations here

https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

and it states that I can use

%H and %M and %S for hours, minutes and seconds

I do this:

datetime.date.today().strftime("%Y-%m-%d %H:%M:%S")

and I always get

'2016-07-18 00:00:00'

where are the values ?

0

1 Answer 1

52

You are asking for a date, which doesn't include a time. You want a datetime:

datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Example:

In [3]: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Out[3]: '2016-07-18 18:26:18'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.