python获取时间 毫秒计算
import time
def get_time_stamp():
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - int(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
print(time_stamp)
stamp = ("".join(time_stamp.split()[0].split("-"))+"".join(time_stamp.split()[1].split(":"))).replace('.', '')
print(stamp)
if __name__ == '__main__':
get_time_stamp()
2018-04-17 15:28:28.434
20180417152828434
获取毫秒时间,python之中有秒,微秒的计算。
def getTickTimes():
#start = round(time.time() * 1000)
#print (start)
start_ = datetime.utcnow()
print(start_)
time.sleep(1)
#end = round(time.time() * 1000)
#print(end)
end_ = datetime.utcnow()
print(end_)
c = (end_ - start_)#
print(c.seconds)
print(c.seconds*1000+c.microseconds/1000)#毫秒时间
print( c)
print(c / 2)
2019-01-02 07:50:06.287000
2019-01-02 07:50:07.287000
1
microseconds/1000: 0
0:00:01
0:00:00.500000