【问题标题】:What is the Python time string format for this?什么是 Python 时间字符串格式?
【发布时间】:2019-01-25 18:51:17
【问题描述】:

我正在尝试为 Python 时间模块的这个时间字符串找到正确的时间格式:

'2019-01-25T06:59:36.8081116Z'

我尝试了这个'%Y-%m-%dT%H:%M:%SZ' 和许多变体,但都无法正确。

文档链接: https://docs.python.org/2/library/time.html

【问题讨论】:

  • 您能否为您的代码添加更多上下文以及错误消息是什么?

标签: python datetime time timestamp


【解决方案1】:

这可能会有所帮助

import datetime
curtime = datetime.datetime.now()
curtime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")

不知道如何获得小数点后 7 位。也许你的字符串以 '6Z' 而不是 'Z' 结尾?

【讨论】:

  • 我正在尝试:import time 然后time.strptime('2019-01-25T06:59:36.8081116Z', "%Y-%m-%dT%H:%M:%S.%fZ") 来获取时间结构,但它不起作用。错误为 ValueError:时间数据 '2019-01-23T06:59:36.8081116Z' 与格式 '%Y-%m-%dT%H:%M:%S.%fZ' 不匹配
  • 时间没有 %f
猜你喜欢
  • 1970-01-01
  • 2016-12-14
  • 2016-12-29
  • 2022-04-08
  • 1970-01-01
  • 2020-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多