小编Tom*_*ers的帖子

python datetime timestrp函数错误

我试图从txt文件中获取日期时间.在该文件中的时间呈现[]它周围.

我知道第一行总是一个时间戳.但是当我尝试使用strptime获取日期时间时,我收到一条错误消息.

我搜索了其他解决方案.但似乎没有发现任何符合我的错误.

码:

FileYSI = open(FilenameYSI,'r')
TimeStampYSI = [next(FileYSI)for x in xrange(1)]

print TimeStampYSI[0]
if TimeStampYSI[0][0] == '['
    TimeFP = time.strptime(TimeStampYSI[0],'[%y-%m-%d,%H:%M:%S.%f]\n')
Run Code Online (Sandbox Code Playgroud)

错误:

[2015-09-22,08:10:00.600000]


Traceback (most recent call last):
  File "C:/Users/brondert/Documents/realtime_data_aquadrone/trunk/src/MergeLogs.py", line 129, in <module>
    MergeLogs("test")
  File "C:/Users/brondert/Documents/realtime_data_aquadrone/trunk/src/MergeLogs.py", line 92, in MergeLogs
    TimeFP = time.strptime(TimeStampYSI[0],'[%y-%m-%d,%H:%M:%S.600000]\n')
  File "C:\Python27\lib\_strptime.py", line 467, in _strptime_time
    return _strptime(data_string, format)[0]
  File "C:\Python27\lib\_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data '[2015-09-22,08:10:00.600000]\n' does not match format '[%y-%m-%d,%H:%M:%S.600000]\n'
Run Code Online (Sandbox Code Playgroud)

python datetime strptime

1
推荐指数
1
解决办法
96
查看次数

标签 统计

datetime ×1

python ×1

strptime ×1