博客专栏

EEPW首页>博客> Python3将时间戳转换为指定格式日期

Python3将时间戳转换为指定格式日期

发布人:电子禅石 时间:2021-05-20 来源:工程师 发布文章

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

当前时间

实例一

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

实例二

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

指定时间戳

实例三

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

实例四

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



importtime
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)


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。



关键词:python

相关推荐

技术专区

关闭