python中时间戳与日期的互相转化
当前时间:
ymdhms = time.strftime(‘%Y-%m-%d %H:%M:%S’,time.localtime(time.time())) timeArray = time.strptime(ymdhms, “%Y-%m-%d %H:%M:%S”)
当前时间日期戳:
currentTimeStamp = int(time.mktime(timeArray)) print(currentTimeStamp)
将时间戳再转为日期:
timeArray = time.localtime(currentTimeStamp) aTime = time.strftime(“%Y-%m-%d %H:%M:%S”, timeArray) print(aTime)