I am able to get the current time as this:
import datetime
str(datetime.date.today().strftime("%Y-%m-%d"))
that prints
2016-06-26
but i need to add the minutes and seconds and hour
i search on internet and people are suggesting using this:
str(datetime.date.today().strftime("%Y-%m-%d %H:%M"));
but actually the %H:%M returns 00:00 always
can you help ?
Use
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2016-06-26 14:15:44'
You can even use .today() instead of .now().
datetime.date.today() is of type <type 'datetime.date'> which basically returns only the date. That is why your hours and minutes when printed returns 00:00.
Hence, if you use datetime.datetime.now() this would return type <type 'datetime.datetime'> which is a datetime object, you'll get the date and the time.
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