Python获取秒级时间戳与毫秒级时间戳
2017-07-12 10:08
561 查看
1、获取秒级时间戳与毫秒级时间戳
import time import datetime t = time.time() print (t) #原始时间数据 print (int(t)) #秒级时间戳 print (int(round(t * 1000))) #毫秒级时间戳 nowTime = lambda:int(round(t * 1000)) print (nowTime()); #毫秒级时间戳,基于lambda print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) #日期格式化
返回
1499825149.26 1499825149 1499825149257 1499825149257 2017-07-12 10:05:49
2、将日期转为秒级时间戳
dt = '2018-01-01 10:40:30' ts = int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S"))) print (ts)
返回
1514774430
3、将秒级时间戳转为日期
ts = 1515774430 dt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)) print(dt)
返回
2018-01-13 00:27:10
相关文章推荐
- 利用Python获取系统当前时间
- 通过python获取微秒时间
- Python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- Linux获取毫秒级时间
- Python 获取当前时间
- python 获取当前时间
- python练习程序(获取系统当前时间)
- python 获取网络时间及修改本地时间
- 获取系统时间精确到毫秒级
- C++ 获取当前日期时间 毫秒级
- Python实例讲解 -- 获取本地时间日期(日期计算)
- python读配置文件;正则表达式替换、切割字符串;获取当前时间
- 利用python获取linux系统时间
- python 获取时间
- python学习之获取当前时间的方法(可以任意取时间的任何一个对象显示)
- Python-获取文件最后修改时间
- 关于python获取当前时间的方法
- python 获取当前时间