python utc datetime转换为时间戳的方法
作者:death_include 时间:2021-11-18 07:11:44
最近python代码遇到了一个神奇的需求, 就是如果将python utc datetime转换为时间戳.
百度找到都是使用time.mktime(xxx) 但是看到官网文档里写
time.mktime(t)
This is the inverse function of localtime()
而且亲测 这样将UTC datetime格式的转换完并不是utc时间戳. 这里会当作带时间戳的datetime来处理.
正确的做法是:
import calendar
calendar.timegm(tuple)
只不过这里需要将 datetime对象调用timetuple()方法才OK哦!
来源:https://blog.csdn.net/death_include/article/details/80013138
标签:python,utc,datetime,时间戳
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3安装pip工具的详细步骤
2021-09-27 15:38:09
![](https://img.aspxhome.com/file/2023/3/72923_0s.png)
Python读入mnist二进制图像文件并显示实例
2023-04-23 16:40:44
Tensorflow: 从checkpoint文件中读取tensor方式
2022-07-20 11:39:29
什么是网站灵魂?
2007-09-08 08:25:00
文字的减法
2007-11-06 12:58:00
python去除删除数据中\\u0000\\u0001等unicode字符串的代码
2023-09-04 09:15:51
Python3使用SMTP发送带附件邮件
2022-02-10 12:05:53
![](https://img.aspxhome.com/file/2023/8/63208_0s.jpg)
关于Python包导入报错的问题总结
2021-02-05 18:13:46
![](https://img.aspxhome.com/file/2023/7/75257_0s.png)
getAllResponseHeaders获取网页的http头信息代码
2010-03-31 14:31:00
Python3爬虫RedisDump的安装步骤
2023-07-17 00:42:15
如何使用python docx模块操作word文档
2022-04-23 12:16:02
![](https://img.aspxhome.com/file/2023/6/76086_0s.png)
使用ajax开发的五大误区
2008-09-03 12:46:00
python list.sort()根据多个关键字排序的方法实现
2021-05-22 03:16:09
asp解决防止表单重复提交的方法
2007-10-19 18:40:00
秒杀场景的缓存、队列、锁使用Redis优化设计方案
2023-05-29 19:07:18
![](https://img.aspxhome.com/file/2023/9/55339_0s.png)
ASP.NET Core MVC基础学习之局部视图(Partial Views)
2023-07-19 21:02:37
基于Python制作一个简单的文章搜索工具
2021-07-08 02:16:28
![](https://img.aspxhome.com/file/2023/1/65851_0s.webp)
PyQt5实现暗黑风格的计时器
2023-07-07 02:49:30
![](https://img.aspxhome.com/file/2023/0/61990_0s.jpg)
asp使用ServerVariables集合
2008-02-27 13:22:00
![](https://img.aspxhome.com/file/UploadPic/20082/27/2008227132759154s.jpg)
ecshop百度编辑器远程下载无后缀的图片,并且加水印
2023-08-14 17:31:41