脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python如何快速生成时间戳

python如何快速生成时间戳

2020-07-22 00:06流芳 Python

在本篇内容里小编给大家整理的是关于python生成时间戳的简单方法,需要的朋友们可以学习下。

?
1
2
3
4
5
import time
 
now_time = time.time()
 
print(now_time)

结果是

?
1
1594604269.1730552

知识点扩展:

获取秒级时间戳与毫秒级时间戳、微秒级时间戳

?
1
2
3
4
5
6
7
import time
import datetime
t = time.time()
print (t)   #原始时间数据
print (int(t))   #秒级时间戳
print (int(round(t * 1000))) #毫秒级时间戳
print (int(round(t * 1000000))) #微秒级时间戳

返回

?
1
2
3
4
1499825149.257892 #原始时间数据
1499825149  #秒级时间戳,10位
1499825149257 #毫秒级时间戳,13位
1499825149257892 #微秒级时间戳,16位

获取当前日期时间

?
1
2
3
4
dt = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
dt_ms = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 含微秒的日期时间,来源 比特量化
print(dt)
print(dt_ms)

返回

?
1
2
2018-09-06 21:54:46
2018-09-06 21:54:46.205213

到此这篇关于python如何快速生成时间戳的文章就介绍到这了,更多相关python生成时间戳的简单方法内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.py.cn/jishu/jichu/19543.html

延伸 · 阅读

精彩推荐