python – 获取时间戳(10位和13位)「建议收藏」
Python 获取 建议 时间 收藏 10 13
2023-06-13 09:14:52 时间
大家好,又见面了,我是你们的朋友全栈君。
在python 开发web程序时,需要调用第三方的相关接口,在调用时,需要对请求进行签名。需要用到unix时间戳。 在python里,在网上介绍的很多方法,得到的时间戳是10位。而java里默认是13位(milliseconds,毫秒级的)。
下面介绍python获得时间戳的方法:
1、10时间戳获取方法:
>>> import time
>>> t = time.time()
>>> print t
1436428326.76
>>> print int(t)
1436428326
>>>
强制转换是直接去掉小数位。
2、13位时间戳获取方法:
(1)默认情况下python的时间戳是以秒为单位输出的float
>>>
>>> import time
>>> time.time()
1436428275.207596
>>>
通过把秒转换毫秒的方法获得13位的时间戳:
import time
millis = int(round(time.time() * 1000))
print millis
round()是四舍五入。
(2)
import time
current_milli_time = lambda: int(round(time.time() * 1000))
Then:
>>> current_milli_time()
1378761833768
13位时间 戳转换成时间:
>>> import time
>>> now = int(round(time.time()*1000))
>>> now02 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(now/1000))
>>> now02
'2017-11-07 16:47:14'
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/186701.html原文链接:https://javaforall.cn
相关文章
- python re.compile() 详解——Python正则表达式「建议收藏」
- Python获取时间戳_python爬虫时间戳
- Python多线程通信_python socket多线程
- python 生成数组_Python创建数组「建议收藏」
- python编程是啥-Python编程「建议收藏」
- python jieba库_Python jieba库的使用说明「建议收藏」
- python爬虫—–Python访问http的几种方式「建议收藏」
- unboundlocalerror python_Python问题:UnboundLocalError: local variable ‘xxx’ referenced before assignme
- python基础(8)python中is和==的区别详解
- python生成器详解_Python 生成器
- Python.win32gui.获取窗体「建议收藏」
- Python获取当前位置所在行数以及函数名
- 【说站】python计算列表项出现次数的方法
- 基于LSTM的股票预测模型_python实现_超详细
- Python 自动获取 Bing 壁纸
- python lambda表达式举例_Python中lambda表达式[通俗易懂]
- python抛出异常写法_零基础学 Python(32):如何抛出和捕获异常?「建议收藏」
- Python文件名后缀_python获取目录下所有文件的文件名
- Python绘制旭日图_python绘制散点图
- python程序化交易实例-用 Python 实现你的量化交易策略「建议收藏」
- python使用opencv如何保存图片_OpenCV Python 保存图片
- Python爬虫爬取百合网的男性h
- Python使用platform库获取系统信息:操作系统信息、硬件信息、python环境信息
- Python学习:1.快速搭建python环境详解编程语言
- 在Linux上安装Python学习快乐(linux下载python)