import time , datetime
# 日期转换时间戳
date_time = '2019-07-03 18:27:05'
# 转换为时间数组
array = time.strptime(date_time, "%Y-%m-%d %H:%M:%S")
print(array)
print(array.tm_year)
print(array.tm_mon) # 7
print(array.tm_mday) # 3
print(array.tm_hour)
print(array.tm_min)
print(array.tm_sec) #5
timestamp = int(time.mktime(array))
print(timestamp)
# 更换显示格式
otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", array)
print(otherStyleTime)
# 时间戳转换为指定格式日期
timeStamp = 1562149625
timenow = time.localtime(timeStamp)
print(timenow)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timenow)
print otherStyleTime
# 使用datetime
timeStamp = 1562149625
dateArray = datetime.datetime.utcfromtimestamp(timeStamp)
otherStyleTime = dateArray.strftime("%Y--%m--%d %H:%M:%S")
print otherStyleTime