Python获取本地时间戳包含毫秒
Python可以通过datetime模块来获取本地时间戳包含毫秒,具体方法如下:
- 1、导入datetime模块:
import datetime
- 2、获取当前时间:
now = datetime.datetime.now()
- 3、将当前时间转换为时间戳:
timestamp = datetime.datetime.timestamp(now)
- 4、获取毫秒:
milliseconds = now.microsecond/1000
将时间戳和毫秒拼接在一起就可以得到本地时间戳包含毫秒了。