time函数python_Python time strptime()方法

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

#!/usr/bin/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***[email protected]年前 (2018-06-04)

你可能感兴趣的:(time函数python)