我有以下代码:
import datetime
Today = datetime.date.today()
print (Today.strftime("%m/%d/%Y-%H:%M:%S"))
获取输出11/28/2015-00:00:00
。如何使其显示正确的小时,分钟和秒,而不仅仅是零?
答案 0 :(得分:1)
只需使用datetime.datetime.now()
代替datetime.date.today()
:
In [8]: today = datetime.datetime.now()
In [9]: print (today.strftime("%m/%d/%Y-%H:%M:%S"))
11/29/2015-10:27:32