将大纪元时间转换为本地时间
Convert Epoch time to local time
log_input.log
1949,1603441909,984159,0.002608,19.8829994202,0.0,640.0
950,1603441910, 416274
21,160340, 24666082,0.002608,19.81913,0.0,638.0
检查列的一致性,列号不一致的忽略该行。读取第二列并将第二列转换为本地时间格式。
log_output.log
1949, 10-31-49,984159,0.002608,19.8829994202,0.0,640.0
21, 9-32-20, 24666082,0.002608,19.81913,0.0,638.0
代码:
with open('log_input.txt', 'r') as f:
csv_data = csv.reader(f)
csv_lines = list(csv_data)
for line in csv_lines:
line[1] = convert(line[1].split(':')[1].strip())
您可以使用日期时间将纪元转换为日期:
time.strftime('%Y-%m-%d', time.localtime(<your epoch>))
如果不到一天,只要检查是否小于86400,如果是,就照原样写。
log_input.log
1949,1603441909,984159,0.002608,19.8829994202,0.0,640.0
950,1603441910, 416274
21,160340, 24666082,0.002608,19.81913,0.0,638.0
检查列的一致性,列号不一致的忽略该行。读取第二列并将第二列转换为本地时间格式。
log_output.log
1949, 10-31-49,984159,0.002608,19.8829994202,0.0,640.0
21, 9-32-20, 24666082,0.002608,19.81913,0.0,638.0
代码:
with open('log_input.txt', 'r') as f:
csv_data = csv.reader(f)
csv_lines = list(csv_data)
for line in csv_lines:
line[1] = convert(line[1].split(':')[1].strip())
您可以使用日期时间将纪元转换为日期:
time.strftime('%Y-%m-%d', time.localtime(<your epoch>))
如果不到一天,只要检查是否小于86400,如果是,就照原样写。