From e260c1679500dffa67a74ba2ca6285432f440aea Mon Sep 17 00:00:00 2001 From: msincenselee Date: Tue, 25 Jan 2022 16:08:14 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=20=E8=8E=B7=E5=8F=96csv=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E6=97=A5=E6=9C=9F=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/utility.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index e31e3c33..ff888fba 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -361,7 +361,14 @@ def get_csv_last_dt(file_name, dt_index=0, dt_format='%Y-%m-%d %H:%M:%S', line_l datas = row.split(',') if len(datas) > dt_index + 1: try: - last_dt = datetime.strptime(datas[dt_index], dt_format) + s = datas[dt_index] + # 检查毫秒不要超过6位长度 + if '.' in dt_format and '.' in s: + i = s.find('.') + if len(s) - i -1 > 6: + len_ms = len(s) - i -1 + s = s[:-(len_ms-6)] + last_dt = datetime.strptime(s, dt_format) return last_dt except: # noqa return None