python 获取毫秒级时间戳
作者:解琛
时间:2020 年 8 月 10 日
时间戳的获取方法如下。
#!/usr/bin/env python
# coding=utf-8
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 - long(ct)) * 1000
time_stamp = "%s%03d" % (data_head, data_secs)
return time_stamp
if __name__ == "__main__":
print get_time_stamp()
运行结果如下。
xiechen@xiechen-Ubuntu:~/文档/6.全世科技/3.2212协议/client$ python client.py
20200810135256008