使用dateTime.strptime()时会遇到值错误

发布于 2025-02-11 09:57:38 字数 290 浏览 2 评论 0原文

我正在使用dateTime.strptime(),以转换从API接收到的TimesATMP字符串以分开日期和时间。一个示例之一:

from datetime import 
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%f%

我不知道此“ 2019-11-14T03:41:12.869000Z”,“%y-%m-%dt%h:%m:%m:%s 。%f%z“

i am using datetime.strptime()in order to convert the timesatmp string received from the API to separate the date and time. one of the example :

from datetime import 
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%f%

and I can't figure out what is wrong with this "2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%f%Z" ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日浅笑〃 2025-02-18 09:57:39

%z IS 时区名称(如果对象是幼稚的,如果对象是空的) 。例如UTC。如果尾随z出现在您的所有字符串中使用z而不是%z,那就是

import datetime
dt = datetime.datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")
print(dt)

输出

2019-11-14 03:41:12.869000

%Z is Time zone name (empty string if the object is naive). for example UTC. If trailing Z appears in all your strings use Z rather than %Z, that is

import datetime
dt = datetime.datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")
print(dt)

output

2019-11-14 03:41:12.869000
梦行七里 2025-02-18 09:57:39

只需在Z之前删除%,它应该可以工作!

from datetime import datetime
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")

Just remove the % before Z and it should work!

from datetime import datetime
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文