問題
python3代碼轉換時間字符串->時間戳(秒級)時報錯如上,代碼如下:
#time_stamp:"2019-09-01 12:12:12"
def get_timestamp(time_string):
t = time.strptime(time_string, "%Y-%m-%d %H:%M:%S")
# 將時間元組轉時間戳
timestamp = int(time.mktime(t))
return timestamp
解決
從csv文件中讀取的time_string值有的爲null,導致出錯。應該在轉換之前判空,過濾掉爲null的數據。