最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
基于python获取本地时间并转换时间戳和日期格式代码示例
时间:2020-10-27 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下基于python获取本地时间并转换时间戳和日期格式代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
附上代码与运行结果截图:
import time # 获取当前时间 now = time.localtime() # 格式化日期 now_ = time.strftime('%Y-%m-%d %H:%M:%S', now) # 获取当前时间,以时间戳格式 now_stamp = time.time() # 日期转时间戳 change_to_stamp = time.mktime(time.strptime(now_, "%Y-%m-%d %H:%M:%S")) # 时间戳转日期 change_to_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now_stamp)) print(now) print(now_) print(now_stamp) print(change_to_stamp) print(change_to_time)
运行截图如下:
-
上一个: Python字符串查找基本操作案例解析
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27