1、获取时间戳(返回结果:1600856115.584483)
import time
timeStamp = time.time() # 时间戳:1600856115.584483
2、时间戳 --> 日期格式:(返回结果:‘Wed Sep 23 18:15:15 2020’)
timeDate = time.ctime(timeStamp)
3、时间戳 --> 日期格式:(返回结果:datetime.datetime(2020, 9, 23, 18, 15, 15))
timeDate = parser.parse(time.ctime(timeStamp)) # datetime.datetime(2020, 9, 23, 18, 15, 15)
timeDate = dt.datetime.fromtimestamp(timeStamp) # datetime.datetime(2020, 9, 23, 18, 15, 15, 584483)
4、时间戳 --> 日期格式:(返回结果:datetime.date(2020, 9, 23))
timeDate = parser.parse(time.ctime(timeStamp)).date()
timeDate = dt.datetime.fromtimestamp(timeStamp).date()
timeDate = dt.date.fromtimestamp(timeStamp)
5、时间戳 --> 时间元组
timeArray = time.localtime(timeStamp)
timeArray = time.gmtime(timeStamp)
# 返回结果:time.struct_time(tm_year=2020, tm_mon=9, tm_mday=23, tm_hour=18, tm_min=15, tm_sec=15, tm_wday=2, tm_yday=267, tm_isdst=0)