创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
这篇文章主要介绍python3中时间戳/时间/日期的转换和加减的案例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
1.当前时间戳转换为指定格式的日期
# -*- coding: utf-8 -*- # @Time : 2019/5/31 10:56 # @Author : 甄超锋 # @Email : 4535@sohu.com # @File : test.py # @Software: PyCharm import datetime import time # 使用time timeStamp = time.time() # 1559286774.2953627 timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) print(otherStyleTime) # 2019-05-31 15:12:54 # 使用datetime timeStamp = time.time() # 1559286774.2953627 dateArray = datetime.datetime.utcfromtimestamp(timeStamp) otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S") print(otherStyleTime) # 2019-05-31 07:12:54