·Python 获取本地时间戳(包含毫秒)

xiaoxiao2021-03-01  21

Python 获取本地时间戳(包含毫秒)

如何通过 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.d" % (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第一行为:年-月-日 时:分:秒 . 毫秒

第二行为拼接后时间戳

转载请注明原文地址: https://www.6miu.com/read-3100023.html

最新回复(0)