首页 > 编程知识 正文

python strptime函数Python time strptime方法,python的方法和函数

时间:2023-05-04 15:24:32 阅读:238307 作者:4766

分享一个获取含毫秒的当前时间的方法:

#!/usr/dldzfj/python

# -*- coding: UTF-8 -*-

import time

def get_current_time():

"""[summary] 获取当前时间

[description] 用time.localtime()+time.strftime()实现

:returns: [description] 返回str类型

"""

ct = time.time()

local_time = time.localtime(ct)

data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)

data_secs = (ct - long(ct)) * 1000

time_stamp = "%s.%03d" % (data_head, data_secs)

return time_stamp

print get_current_time()

输出结果类似如下:

2018-06-04 19:06:32.641

夜歌

夜歌

ren***1068@sina.com3年前 (2018-06-04)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。