gpt4 book ai didi

python - '020-06-08 17 :11:02+00:00' I want to extract the date from this time format in Python using datetime

转载 作者:行者123 更新时间:2023-12-01 09:20:52 25 4
gpt4 key购买 nike

这就是我所拥有的

date = datetime.datetime.strptime('2020-06-08 17:11:02+00:00', '%Y-%m-%d %H:%M:%S+%f')
d= date.strftime('%Y-%m-%d')
print(d);

最佳答案

这是一种方法。由于您只需要日期,我已从原始日期字符串中删除了 :00

演示:

import datetime

sData = '2020-06-08 17:11:02+00:00'

date = datetime.datetime.strptime(sData[:-3], '%Y-%m-%d %H:%M:%S+%f')
d = date.strftime('%Y-%m-%d')
print(d)

输出:

2020-06-08

关于python - '020-06-08 17 :11:02+00:00' I want to extract the date from this time format in Python using datetime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50791803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com