简体   繁体   English

获取python中时间的时间戳格式

[英]Get the time stamp format of time in python

How can i get this format of time in python is there any suggestion about it我怎样才能在 python 中获得这种时间格式,有什么建议吗?

var ti = Date.now() + parseFloat(Math.random().toFixed(8))
1609193057063.8418

You can do this:你可以这样做:

from datetime import datetime

print(datetime.now().timestamp())

Or simpler:或更简单:

import time

print(time.time())

Which will output:

1609193535.115763

You can then, using slicing, cut the decimals at the end or just use the decimal stdlib to aproximate the last 4 decimals.然后,您可以使用切片,在末尾截取小数,或者只使用decimal stdlib 来近似最后 4 位小数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM