【发布时间】:2018-03-01 07:37:29
【问题描述】:
在 python 中,我如何生成这种特定格式的时间戳?
2010-03-20T10:33:22-07
我搜索了高低,但找不到描述生成这种特定格式的正确术语。
【问题讨论】:
在 python 中,我如何生成这种特定格式的时间戳?
2010-03-20T10:33:22-07
我搜索了高低,但找不到描述生成这种特定格式的正确术语。
【问题讨论】:
您可以将日期时间与strftime 一起使用。示例:
import datetime
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
print(date)
将打印:
2017-09-20T12:59:43.888955
【讨论】:
strftime()的文档页面:docs.python.org/2/library/…
看下面的例子:
import datetime
now = datetime.datetime.now()
now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
这可能会导致以下结果: '2017-09-20T11:52:32-98'
【讨论】:
now.isoformat(),我发现95%的时间都满足我的用例