python从时间开始获得异型日期
我有此字符串:
date_string =“ 2022-04-11 00:00:00.000000”
,我试图转换为此格式:
“ 2022-04-11t00:00:00.000 Z”
date = 我尝试这样做的同样
,但是像无效格式一样遇到错误
datetime.strptime(date_string, "%Y-%m-%dT %H:%M:%S%z")
I have this string:
date_string = "2022-04-11 00:00:00.000000"
which I'm trying to convert to this format:
date = "2022-04-11T00:00:00.000Z"
Can anyone please help me with the same
i tried to do this but am getting Error like invalid format
datetime.strptime(date_string, "%Y-%m-%dT %H:%M:%S%z")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个被称为dateutil的图书馆。
在此的帮助下,我们将字符串解析为日期格式,然后将其转换为ISOUMAT。
导入dateutil.parser作为解析器
date_string =“ 2022-04-11 00:00:00.000000:00.000000”
date = parser.parser.parse.parse(date_string)
< < < <代码> print(date.strftime('%y-%m-%dt%h:%m:%sz'))
输出将为
2022-04-11T00:00:00Z
There's a library known as dateutil.
With the help of that, we parse the string into date format and then we convert it into the isoformat.
import dateutil.parser as parser
date_string = "2022-04-11 00:00:00.000000"
date = parser.parse(date_string)
print(date.strftime('%Y-%m-%dT%H:%M:%SZ'))
The output would be
2022-04-11T00:00:00Z