Python3将时间戳转换为指定格式日期
如何在Python3中将时间戳转换为指定格式日期,首先给定一个时间戳,将其转换为指定格式的时间。下面我们用几个实例来获取当前时间和指定时间戳。
当前时间
实例一

执行以上代码输出结果为:

实例二

执行以上代码输出结果为:

指定时间戳
实例三

执行以上代码输出结果为:

实例四

执行以上代码输出结果为:

import time
val = input('请输入下载时间戳: ')
print(val)
time_start = 1072915200
result = time_start + int(val) #+ 548477434
print(result)
timeArray = time.localtime(result)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)
val =input("请在此输入现在的时间戳: ")
print(val)
timeArray = time.localtime(int(val))
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。