日期和时间戳的转换
def unix_time(dt):
"""
日期转时间戳
:param dt:
:return:
"""
# 转换成时间数组
timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
# 转换成时间戳
timestamp = int(time.mktime(timeArray))
return timestamp
def custom_time(timestamp):
"时间戳转日期"
# 转换成localtime
time_local = time.localtime(timestamp)
# 转换成新的时间格式(2016-05-05 20:28:54)
dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
return dt