ValueError:未转换的数据保留:02:05

发布于 2021-01-29 16:51:21

我在json文件中有一些日期,我正在寻找与今天的日期相对应的日期:

import  os
import time
from datetime import datetime
from pytz import timezone

input_file  = file(FILE, "r")
j = json.loads(input_file.read().decode("utf-8-sig"))

os.environ['TZ'] = 'CET'

for item in j:
    lt = time.strftime('%A %d %B')
    st = item['start']
    st = datetime.strptime(st, '%A %d %B')

    if st == lt :
        item['start'] = datetime.strptime(st,'%H:%M')

我有这样的错误:

File "/home/--/--/--/app/route.py", line 35, in file.py

st = datetime.strptime(st, '%A %d %B')

File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime

data_string[found.end():])

ValueError: unconverted data remains: 02:05

你有什么建议吗 ?

关注者
0
被浏览
42
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    stat之st = datetime.strptime(st, '%A %d %B')类的值,01 01 2013 02:05并且strptime无法解析。确实,您除了日期外还有一个小时……您需要%H:%M在strptime上添加。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看