python
来源:互联网 发布:linux 1.6 rpm bin 编辑:程序博客网 时间:2024/06/16 17:44
在python 开发web程序时,需要调用第三方的相关接口,在调用时,需要对请求进行签名。需要用到unix时间戳。
在python里,在网上介绍的很多方法,得到的时间戳是10位。而java里默认是13位(milliseconds,毫秒级的)。
下面介绍python获得时间戳的方法:
1、10时间戳获取方法:
>>> import time>>> t = time.time()>>> print t1436428326.76>>> print int(t)1436428326>>>
强制转换是直接去掉小数位。
2、13位时间戳获取方法:
(1)默认情况下python的时间戳是以秒为单位输出的float
>>> >>> import time>>> time.time()1436428275.207596>>>
通过把秒转换毫秒的方法获得13位的时间戳:
import timemillis = int(round(time.time() * 1000))print millis
round()是四舍五入。
(2)
import timecurrent_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'
阅读全文
1 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- webView中遇到一些坑
- TP5引入静态资源文件
- leetCode 85. Maximal Rectangle
- HTTP 返回状态代码详解
- Linux Bash之select
- python
- jsp ---打印设置
- MV3D -- 3D proposal 网络
- UITextView的PlaceholderTextView封装Swift4.0
- bzoj 5056: OI游戏
- CentOS6.5 VPS安装PPTP VPN
- 将javaBean转换成XML
- CImg库介绍
- DevExpress软件的安装及首次使用流程讲解