新闻  |   论坛  |   博客  |   在线研讨会
Python3将时间戳转换为指定格式日期
电子禅石 | 2021-05-20 09:43:34    阅读:7961   发布文章

如何在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)


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

参与讨论
登录后参与讨论
属于自己的技术积累分享,成为嵌入式系统研发高手。
推荐文章
最近访客