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 ?
This is mostly because for such objects, %f means "fiscal year".
The strftime() function is used to convert date and time objects to their string representation. It takes one or more input of formatted code and returns the string representation. Returns : It returns the string representation of the date or time object. List of format codes : Reference table for the format codes.
strptime is short for "parse time" where strftime is for "formatting time". That is, strptime is the opposite of strftime though they use, conveniently, the same formatting specification.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With