【发布时间】:2014-03-04 07:26:38
【问题描述】:
我正在尝试以字符串形式获取当前本地时间,格式为:年-月-日时:分:秒。我将用于记录。通过阅读文档,我可以通过以下方式做到这一点:
import time
'{0:%Y-%m-%d %H:%M:%S}'.format(time.localtime())
但是我得到了错误:
回溯(最近一次通话最后): 文件“”,第 1 行,在 ValueError:格式说明符无效我做错了什么?有没有更好的办法?
【问题讨论】:
标签: python python-3.x datetime python-3.3