基于python获取本地时间并转换时间戳和日期格式
作者:铁扇公主 时间:2021-02-23 17:30:06
附上代码与运行结果截图:
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)
运行截图如下:
来源:https://www.cnblogs.com/princessironfan/p/13831277.html
标签:python,本地,时间,戳,日期
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
段正淳的css笔记(6)-浅谈css框架开发
2008-01-13 22:42:00
![](https://img.aspxhome.com/file/UploadPic/20081/13/2008113224547397s.gif)
MySQL安全性指南 (2)
2010-07-26 13:26:00
go smtp实现邮件发送示例详解
2023-06-23 22:05:14
![](https://img.aspxhome.com/file/2023/0/72730_0s.png)
如何检测Oracle的ODBC是否连接成功?
2009-11-24 20:31:00
初学MySql5 所应了解的知识和常见问题
2009-03-06 17:49:00
python特性语法之遍历、公共方法、引用
2023-05-17 16:21:29
不支持RSS,如何跟踪网站的内容更新?
2008-09-08 12:38:00
Python构建简单线性回归模型
2021-03-22 19:58:42
![](https://img.aspxhome.com/file/2023/8/79738_0s.png)
Python实现基于SVM的分类器的方法
2023-11-18 18:20:02
js控制表单不能输入空格的小例子
2013-07-21 11:58:51
Silverlight VS Flash,谁更强?
2008-11-07 11:04:00
Django 中间键和上下文处理器的使用
2022-04-19 05:04:56
![](https://img.aspxhome.com/file/2023/7/83667_0s.png)
有啊在设计上相对淘宝的优势
2009-05-22 12:28:00
PHP中SimpleXML函数用法分析
2023-06-23 11:52:09
python中itertools模块zip_longest函数详解
2023-01-02 09:09:35
对Python获取屏幕截图的4种方法详解
2023-11-19 09:45:41
Python玩转加密的技巧【推荐】
2023-06-26 07:01:31
python数据分析之公交IC卡刷卡分析
2022-02-10 02:23:56
![](https://img.aspxhome.com/file/2023/5/75145_0s.png)
python 实用工具状态机transitions
2023-11-06 21:53:41
Ext.js源码研读总结
2009-03-04 12:06:00