您当前的位置: 首页 >  Python

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

python的时间戳(微秒)

柳鲲鹏 发布时间:2019-02-12 14:29:11 ,浏览量:0

  %f可以输出微秒。具体代码如下:

import datetime

current_time = time.time()

# 秒
seconds = int(current_time)

# 毫秒
mseconds= int(current_time*1000)

# 日期、时间格式化输出。%f可以输出微秒
print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))

# 日期转秒
dt = '2019-02-12 14:32:15'
ts = int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S")))
print(ts)

# 秒转日期。
ts = 1549953233.456123
dt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
print(dt)

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0504s