import time
# 將時間戳轉換成格式化日期
def timestamp_to_str(timestamp=None, format='%Y-%m-%d %H:%M:%S'):if timestamp:time_tuple = time.localtime(timestamp) # 把時間戳轉換成時間元祖result = time.strftime(format, time_tuple) # 把時間元祖轉換成格式化好的時間return resultelse:return time.strptime(format)