我希望将当前时间作为对象传递到strftime引用中。如果我用:
d = date.fromtimestamp(time.time())
print d.strftime("%d-%b-%Y %H:%M:%S")这将打印出时间,但不包括分钟/小时等:
04-Jul-2014 00:00:00 如果我尝试使用不同的调用来尝试获取分钟/小时:
d = date.fromtimestamp(time.localtime())我得到:
TypeError: a float is requiredtime.time()和time.localtime()似乎都包含秒/分钟等内容,但不显示它们。有什么想法?gmtime还返回"AttributeError:'time.struct_time‘对象没有属性'strftime'“。
发布于 2014-07-04 06:04:49
你应该用
from datetime import datetime不
from datetime import date例如:
import time
from datetime import datetime
d = datetime.fromtimestamp(time.time())
print d.strftime("%d-%b-%Y %H:%M:%S")发布于 2014-07-04 06:03:05
使用datetime.fromtimestamp(time.time()),因为date.fromtimestamp(time.time())只绘制日期
d = datetime.fromtimestamp(time.time())
print d
print d.strftime("%d-%b-%Y %H:%M:%S")
#output 04-Jul-2014 11:32:40https://stackoverflow.com/questions/24567382
复制相似问题